Chuyển đến nội dung
Diễn đàn CADViet
Đăng nhập để thực hiện theo  
victor85

[Yêu cầu] viết dùm mình lisp tạo pline này với

Các bài được khuyến nghị

Lệnh pl1:

đối tượng đầu vào là 2 line (pline, arc, ellipse) song song và là đối tượng offset của nhau.

Kết quả tạo ra một pline có bề dày bằng khoảng cách offset và là đường song song ở chính giữa 2 line gốc ban đầu.

Ace ai biết thì bớt chút time viết dùm mình với nhé. mình thanks liền liền hè :)

  • Vote tăng 1
  • Vote giảm 1

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

Lệnh pl1:

đối tượng đầu vào là 2 line (pline, arc, ellipse) song song và là đối tượng offset của nhau.

Kết quả tạo ra một pline có bề dày bằng khoảng cách offset và là đường song song ở chính giữa 2 line gốc ban đầu.

Ace ai biết thì bớt chút time viết dùm mình với nhé. mình thanks liền liền hè :)

Trước hết cần phải có thuật toán đã. Em đề xuất một thuật toán như sau:

1. Chọn hai đường là offset của nhau, sau đó lấy được khoảng cách a mà chúng đã được offset ( pline thì chính là đường vuông góc từ đường này đến đường kia, arc thì là hiệu của bán kính, ellipse cũng là hiệu bán kính)

2. Sau đó thực hiện lệnh offset 1 trong hai đường với khoảng cách offset là 0.5a và định hướng là tới đường còn lại

3. Biến đối tượng vừa vẽ thành pline (nếu như là arc hay ellipse)

4. Set độ dày của pline vừa nhận được là a

5. Xóa 2 đối tượng nhập vào ban đầu

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

Lệnh pl1:

đối tượng đầu vào là 2 line (pline, arc, ellipse) song song và là đối tượng offset của nhau.

Kết quả tạo ra một pline có bề dày bằng khoảng cách offset và là đường song song ở chính giữa 2 line gốc ban đầu.

Ace ai biết thì bớt chút time viết dùm mình với nhé. mình thanks liền liền hè :)

LISP : Vẽ PLINE có bề dày bằng khoảng cách offset của 2 Line (hoặc Arc ) offset của nhau và nằm chính giữa 2 đ/tượng gốc ban đầu.

(defun c:2PL (/ bulge dis ent1 ent2 pt1 pt11 pt12 pt2 ss typ)
 ;;  By : Gia_Bach, www.CadViet.com      ;;  
 (vl-load-com)
 (defun addPline (pt1 pt2 width burge / lst pl)
   (setq lst (list (car pt1)(cadr pt1) (car pt2)(cadr pt2)))
   (setq pl
   (vla-addLightweightpolyline
     (vla-get-modelspace (vla-get-ActiveDocument (vlax-get-Acad-Object)))
     (vlax-make-variant(vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 0 (1- (length lst)))) lst))) )
   (vla-put-ConstantWidth pl width)
   (if (/= 0 burge) (vla-SetBulge pl 0 burge)))

 (defun arcbulge (arc / ang)
   (setq ang (vla-get-TotalAngle (vlax-ename->vla-object arc)))
   (/ (sin (/ ang 4)) (cos (/ ang 4))  )  )
 ;main
 (princ "\nChon Arc hay Line :")
 (and (setq ss (ssget "_+.:S:E" '((0 . "ARC,LINE"))))
      (setq typ (cdr (assoc 0 (entget (setq ent1 (ssname ss 0))))))
      (if (= typ "ARC") (princ "\nChon Arc :")(princ "\nChon Line :"))
      (setq ss (ssget "_+.:S:E" (list (cons 0 typ))))
      (setq ent2 (ssname ss 0))
      (setq pt11 (vlax-curve-getEndPoint ent1)
     pt12 (vlax-curve-getStartPoint ent1)	     
     dis (distance pt11(vlax-curve-getClosestPointTo ent2 pt11))
     pt1 (polar pt11 (angle pt11 (vlax-curve-getEndPoint ent2)) (/ dis 2))
     pt2 (polar pt12 (angle pt12 (vlax-curve-getStartPoint ent2)) (/ dis 2)))
      (if (= typ "ARC") (setq bulge (-(arcbulge ent1))) (setq bulge 0))
      (addPline pt1 pt2 dis bulge)       )
 (princ))

  • Vote tăng 2

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

Lệnh pl1:

đối tượng đầu vào là 2 line (pline, arc, ellipse) song song và là đối tượng offset của nhau.

Kết quả tạo ra một pline có bề dày bằng khoảng cách offset và là đường song song ở chính giữa 2 line gốc ban đầu.

Ace ai biết thì bớt chút time viết dùm mình với nhé. mình thanks liền liền hè :)

Theo mình thì đi hướng như sau có khi dể hơn mà tác dụng như nhau nề:

-Hỏi chọn 1 đối tượng (trong 2 đối tượng nguồn).

-Hỏi chọn điểm vuông góc (lúc này mình chuyển chế độ truy bắt điểm theo kiểu này).

Thực hiện offset đối tượng chọn theo khoảng cách và hướng tính được, đổi thành pline, đổi bề dày.

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

LISP : Vẽ PLINE có bề dày bằng khoảng cách offset của 2 Line (hoặc Arc ) offset của nhau và nằm chính giữa 2 đ/tượng gốc ban đầu.

(defun c:2PL (/ bulge dis ent1 ent2 pt1 pt11 pt12 pt2 ss typ)
 ;;  By : Gia_Bach, www.CadViet.com      ;;  
 (vl-load-com)
 (defun addPline (pt1 pt2 width burge / lst pl)
   (setq lst (list (car pt1)(cadr pt1) (car pt2)(cadr pt2)))
   (setq pl
   (vla-addLightweightpolyline
     (vla-get-modelspace (vla-get-ActiveDocument (vlax-get-Acad-Object)))
     (vlax-make-variant(vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 0 (1- (length lst)))) lst))) )
   (vla-put-ConstantWidth pl width)
   (if (/= 0 burge) (vla-SetBulge pl 0 burge)))

 (defun arcbulge (arc / ang)
   (setq ang (vla-get-TotalAngle (vlax-ename->vla-object arc)))
   (/ (sin (/ ang 4)) (cos (/ ang 4))  )  )
 ;main
 (princ "\nChon Arc hay Line :")
 (and (setq ss (ssget "_+.:S:E" '((0 . "ARC,LINE"))))
      (setq typ (cdr (assoc 0 (entget (setq ent1 (ssname ss 0))))))
      (if (= typ "ARC") (princ "\nChon Arc :")(princ "\nChon Line :"))
      (setq ss (ssget "_+.:S:E" (list (cons 0 typ))))
      (setq ent2 (ssname ss 0))
      (setq pt11 (vlax-curve-getEndPoint ent1)
     pt12 (vlax-curve-getStartPoint ent1)	     
     dis (distance pt11(vlax-curve-getClosestPointTo ent2 pt11))
     pt1 (polar pt11 (angle pt11 (vlax-curve-getEndPoint ent2)) (/ dis 2))
     pt2 (polar pt12 (angle pt12 (vlax-curve-getStartPoint ent2)) (/ dis 2)))
      (if (= typ "ARC") (setq bulge (-(arcbulge ent1))) (setq bulge 0))
      (addPline pt1 pt2 dis bulge)       )
 (princ))

 

Trong này có mấy hàm vlaxxx như : vla-addLightweightpolyline,... nhưng trong bộ Help của AutoCAD về AutoLisp không thấy. Không biết ở đâu có thể tìm thông tin về chúng ạ?

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

Trong này có mấy hàm vlaxxx như : vla-addLightweightpolyline,... nhưng trong bộ Help của AutoCAD về AutoLisp không thấy. Không biết ở đâu có thể tìm thông tin về chúng ạ?

Sao bạn cái gì cũng không có vậy? Khi cài cad từ >=2004 (hình như thế) nếu có cài cả bộ Express (tức là cài đầy đủ) thì vào help là có vl, vlr, vlax luôn. Nợ chưa trả nhé!

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

@Thaistreetz:

Anh nói chuẩn rồi ạ :D

 

@Doan Van Ha:

Đây là những gì có trong bộ help của autolisp về V function:

Topics in this section
vector_image

Draws a vector in the currently active dialog box image


ver

Returns a string that contains the current AutoLISP version number


vl-acad-defun

Defines an AutoLISP function symbol as an external subroutine


vl-acad-undefun

Undefines an AutoLISP function symbol so it is no longer available to ObjectARX applications


vl-arx-import

Imports ObjectARX/ADSRX functions into a separate-namespace VLX


vl-bb-ref

Returns the value of a variable from the blackboard namespace


vl-bb-set

Sets a variable in the blackboard namespace


vl-catch-all-apply

Passes a list of arguments to a specified function and traps any exceptions


vl-catch-all-error-message

Returns a string from an error object


vl-catch-all-error-p

Determines whether an argument is an error object returned from vl-catch-all-apply


vl-cmdf

Executes an AutoCAD command


vl-consp

Determines whether or not a list is nil


vl-directory-files

Lists all files in a given directory


vl-doc-export

Makes a function available to the current document


vl-doc-import

Imports a previously exported function into a VLX namespace


vl-doc-ref

Retrieves the value of a variable from the current document's namespace


vl-doc-set

Sets the value of a variable in the current document's namespace


vl-every

Checks whether the predicate is true for every element combination


vl-exit-with-error

Passes control from a VLX error handler to the *error* function of the calling namespace


vl-exit-with-value

Returns a value to the function that invoked the VLX from another namespace


vl-file-copy

Copies or appends the contents of one file to another file


vl-file-delete

Deletes a file


vl-file-directory-p

Determines if a file name refers to a directory


vl-file-rename

Renames a file


vl-file-size

Determines the size of a file, in bytes


vl-file-systime

Returns last modification time of the specified file


vl-filename-base

Returns the name of a file, after stripping out the directory path and extension


vl-filename-directory

Returns the directory path of a file, after stripping out the name and extension


vl-filename-extension

Returns the extension from a file name, after stripping out the rest of the name


vl-filename-mktemp

Calculates a unique file name to be used for a temporary file


vl-get-resource

Returns the text stored in a .txt file packaged in a VLX


vl-list*

Constructs and returns a list


vl-list->string

Combines the characters associated with a list of integers into a string


vl-list-exported-functions

Lists exported functions


vl-list-length

Calculates list length of a true list


vl-list-loaded-vlx

Returns a list of all separate-namespace VLX files associated with the current document


vl-load-all

Loads a file into all open AutoCAD documents, and into any document subsequently opened during the current AutoCAD session


vl-load-com

Loads Visual LISP extensions to AutoLISP


vl-load-reactors

Loads reactor support functions


vl-mkdir

Creates a directory


vl-member-if

Determines if the predicate is true for one of the list members


vl-member-if-not

Determines if the predicate is nil for one of the list members


vl-position

Returns the index of the specified list item


vl-prin1-to-string

Returns the string representation of LISP data as if it were output by the prin1 function


vl-princ-to-string

Returns the string representation of LISP data as if it were output by the princ function


vl-propagate

Copies the value of a variable into all open document namespaces (and sets its value in any subsequent drawings opened during the current AutoCAD session)


vl-registry-delete

Deletes the specified key or value from the Windows registry


vl-registry-descendents

Returns a list of subkeys or value names for the specified registry key


vl-registry-read

Returns data stored in the Windows registry for the specified key/value pair


vl-registry-write

Creates a key in the Windows registry


vl-remove

Removes elements from a list


vl-remove-if

Returns all elements of the supplied list that fail the test function


vl-remove-if-not

Returns all elements of the supplied list that pass the test function


vl-some

Checks whether the predicate is not nil for one element combination


vl-sort

Sorts the elements in a list according to a given compare function


vl-sort-i

Sorts the elements in a list according to a given compare function, and returns the element index numbers


vl-string->list

Converts a string into a list of character codes


vl-string-elt

Returns the ASCII representation of the character at a specified position in a string


vl-string-left-trim

Removes the specified characters from the beginning of a string


vl-string-mismatch

Returns the length of the longest common prefix for two strings, starting at specified positions


vl-string-position

Looks for a character with the specified ASCII code in a string


vl-string-right-trim

Removes the specified characters from the end of a string


vl-string-search

Searches for the specified pattern in a string 


vl-string-subst

Substitutes one string for another, within a string


vl-string-translate

Replaces characters in a string with a specified set of characters


vl-string-trim

Removes the specified characters from the beginning and end of a string


vl-symbol-name

Returns a string containing the name of a symbol


vl-symbol-value

Returns the current value bound to a symbol


vl-symbolp

Identifies whether or not a specified object is a symbol


vl-unload-vlx

Unload a VLX application that is loaded in its own namespace


vl-vbaload

Loads a VBA project 


vl-vbarun

Runs a VBA macro


vl-vlx-loaded-p

Determines whether a separate-namespace VLX is currently loaded


vlax-3D-point

Creates ActiveX-compatible (variant) 3D point structure


vlax-add-cmd

Adds commands to the AutoCAD built-in command set


vlax-create-object

Creates a new instance of an application object


vlax-curve-getArea

Returns the area inside the curve


vlax-curve-getClosestPointTo

Returns the point (in WCS) on a curve that is nearest to the specified point


vlax-curve-getClosestPointToProjection

Returns the closest point (in WCS) on a curve after projecting the curve onto a plane


vlax-curve-getDistAtParam

Returns the length of the curve's segment from the curve's beginning to the specified parameter


vlax-curve-getDistAtPoint

Returns the length of the curve's segment between the curve's start point and the specified point 


vlax-curve-getEndParam

Returns the parameter of the endpoint of the curve


vlax-curve-getEndPoint

Returns the endpoint (in WCS) of the curve


vlax-curve-getFirstDeriv

Returns the first derivative (in WCS) of a curve at the specified location


vlax-curve-getParamAtDist

Returns the parameter of a curve at the specified distance from the beginning of the curve 


vlax-curve-getParamAtPoint

Returns the parameter of the curve at the point


vlax-curve-getPointAtDist

Returns the point (in WCS) along a curve at the distance specified by the user


vlax-curve-getPointAtParam

Returns the point at the specified parameter value along a curve


vlax-curve-getSecondDeriv

Returns the second derivative (in WCS) of a curve at the specified location


vlax-curve-getStartParam

Returns the start parameter on the curve


vlax-curve-getStartPoint

Returns the start point (in WCS) of the curve


vlax-curve-isClosed

Determines if the specified curve is closed (that is, the start point is the same as the endpoint)


vlax-curve-isPeriodic

Determines if the specified curve has an infinite range in both directions and there is a period value dT, such that a point on the curve at (u + dT) = point on curve (u), for any parameter u


vlax-curve-isPlanar

Determines if there is a plane that contains the curve 


vlax-dump-object

Lists an object's properties, and optionally, the methods that apply to the object


vlax-ename->vla-object

Transforms an entity to a VLA-object


vlax-erased-p

Determines whether an object was erased


vlax-for

Iterates through a collection of objects, evaluating each expression


vlax-get-acad-object

Retrieves the top level AutoCAD application object for the current AutoCAD session


vlax-get-object

Returns a running instance of an application object


vlax-get-or-create-object

Returns a running instance of an application object, or creates a new instance if the application is not currently running


vlax-get-property

Retrieves a VLA-object's property


vlax-import-type-library

Imports information from a type library


vlax-invoke-method

Calls the specified ActiveX method


vlax-ldata-delete

Erases LISP data from a drawing dictionary


vlax-ldata-get

Retrieves LISP data from a drawing dictionary or an object


vlax-ldata-list

Lists LISP data in a drawing dictionary


vlax-ldata-put

Stores LISP data in a drawing dictionary or an object


vlax-ldata-test

Determines if data can be saved over a session boundary


vlax-make-safearray

Creates a safearray


vlax-make-variant

Creates a variant data type


vlax-map-collection

Applies a function to all objects in a collection


vlax-method-applicable-p

Determines if an object supports a particular method


vlax-object-released-p

Determines if an object has been released


vlax-product-key

Returns the AutoCAD Windows registry path


vlax-property-available-p

Determines if an object has a specified property


vlax-put-property

Sets the property of an ActiveX object


vlax-read-enabled-p

Determines if an object can be read


vlax-release-object

Releases a drawing object


vlax-remove-cmd

Removes a single command or a command group


vlax-safearray-fill

Stores data in the elements of a safearray


vlax-safearray-get-dim

Returns the number of dimensions in a safearray object


vlax-safearray-get-element

Returns an element from an array


vlax-safearray-get-l-bound

Returns the lower boundary (starting index) of a dimension of an array


vlax-safearray-get-u-bound

Returns the upper boundary (end index) of a dimension of an array


vlax-safearray-put-element

Adds an element to an array


vlax-safearray-type

Returns the data type of a safearray


vlax-safearray->list

Returns the elements of a safearray in list form


vlax-tmatrix

Returns a suitable representation for a 4 x 4 transformation matrix to be used in VLA methods


vlax-typeinfo-available-p

Determines whether TypeLib information is present for the specified type of object


vlax-variant-change-type

Returns the value of a variant after changing it from one data type to another


vlax-variant-type

Determines the data type of a variant


vlax-variant-value

Returns the value of a variant


vlax-vla-object->ename

Transforms a VLA-object to an AutoLISP entity


vlax-write-enabled-p

Determines if an AutoCAD drawing object can be modified


vlisp-compile

Compiles AutoLISP source code into a FAS file


vlr-acdb-reactor

Constructs a reactor object that notifies when an object is added to, modified in, or erased from a drawing database


vlr-add

Enables a disabled reactor object


vlr-added-p

Tests to determine if a reactor object is enabled 


vlr-beep-reaction

Produces a beep sound


vlr-command-reactor

Constructs an editor reactor that notifies of a command event


vlr-current-reaction-name

Returns the name (symbol) of the current event, if called from within a reactor's callback 


vlr-data

Returns application-specific data associated with a reactor


vlr-data-set

Overwrites application-specific data associated with a reactor 


vlr-deepclone-reactor

Constructs an editor reactor object that notifies of a deep clone event


vlr-docmanager-reactor

Constructs a reactor object that notifies of events relating to drawing documents


vlr-dwg-reactor

Constructs an editor reactor object that notifies of a drawing event (for example, opening or closing a drawing file)


vlr-dxf-reactor

Constructs an editor reactor object that notifies of an event related to reading or writing a DXF file


vlr-editor-reactor

Constructs an editor reactor object


vlr-insert-reactor

Constructs an editor reactor object that notifies of an event related to block insertion


vlr-linker-reactor

Constructs a reactor object that notifies your application every time an ObjectARX application is loaded or unloaded


vlr-lisp-reactor

Constructs an editor reactor object that notifies of a LISP event


vlr-miscellaneous-reactor

Constructs an editor reactor object that does not fall under any other editor reactor types


vlr-mouse-reactor

Constructs an editor reactor object that notifies of a mouse event (for example, a double-click)


vlr-notification

Determines whether or not a reactor will fire if its associated namespace is not active


vlr-object-reactor

Constructs a drawing object reactor object


vlr-owner-add

Adds an object to the list of owners of an object reactor


vlr-owner-remove

Removes an object from the list of owners of an object reactor


vlr-owners

Returns the list of owners of an object reactor


vlr-pers

Makes a reactor persistent


vlr-pers-list

Returns a list of persistent reactors in the current drawing document


vlr-pers-p

Determines whether a reactor is persistent


vlr-pers-release

Makes a reactor transient


vlr-reaction-name

Returns a list of all possible callback conditions for this reactor type


vlr-reaction-set

Adds or replaces a callback function in a reactor


vlr-reactions

Returns a list of pairs (event-name . callback_function) for the reactor


vlr-reactors

Returns a list of existing reactors


vlr-remove

Disables a reactor


vlr-remove-all

Disables all reactors of the specified type


vlr-set-notification

Defines whether a reactor's callback function will execute if its associated namespace is not active


vlr-sysvar-reactor

Constructs an editor reactor object that notifies of a change to a system variable


vlr-toolbar-reactor

Constructs an editor reactor object that notifies of a change to the bitmaps in a toolbar


vlr-trace-reaction

A predefined callback function that prints one or more callback arguments in the Trace window


vlr-type

Returns a symbol representing the reactor type


vlr-types

Returns a list of all reactor types


vlr-undo-reactor

Constructs an editor reactor object that notifies of an undo event


vlr-wblock-reactor

Constructs an editor reactor object that notifies of an event related to writing a block


vlr-window-reactor

Constructs an editor reactor object that notifies of an event related to moving or sizing an AutoCAD window


vlr-xref-reactor

Constructs an editor reactor object that notifies of an event related to attaching or modifying XREFs


vports

Returns a list of viewport descriptors for the current viewport configuration


 

Em có thấy hàm VLA-addLightweightpolyline đâu anh !

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

Trong này có mấy hàm vlaxxx như : vla-addLightweightpolyline,... nhưng trong bộ Help của AutoCAD về AutoLisp không thấy. Không biết ở đâu có thể tìm thông tin về chúng ạ?

Trên diễn đàn có nói nhiều rồi, nhưng chức năng tìm kiếm bay giờ khó sử dụng quá.

 

Đây là 1 vài link :

 

- Rất nhiều hàm khi vào vlide search em không tìm được lời giải đáp...

 

- Một số hàm con VL- hữu ích . Share cùng mọi người

  • Vote tăng 2

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

Trên diễn đàn có nói nhiều rồi, nhưng chức năng tìm kiếm bay giờ khó sử dụng quá.

 

Đây là 1 vài link :

 

- Rất nhiều hàm khi vào vlide search em không tìm được lời giải đáp...

 

- Một số hàm con VL- hữu ích . Share cùng mọi người

 

Cảm ơn bác gia_bach đã viết lisp nhé. Đã test và chạy ngon lắm. Hic nhưng vẫn chưa tổng quát đc lắm. dùng tạm vậy. bác có thể chỉnh sửa version mới cho dễ dùng hơn cho các trường hợp ko vậy?

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

Tạo một tài khoản hoặc đăng nhập để nhận xét

Bạn cần phải là một thành viên để lại một bình luận

Tạo tài khoản

Đăng ký một tài khoản mới trong cộng đồng của chúng tôi. Điều đó dễ mà.

Đăng ký tài khoản mới

Đăng nhập

Bạn có sẵn sàng để tạo một tài khoản ? Đăng nhập tại đây.

Đăng nhập ngay
Đăng nhập để thực hiện theo  

×