visual lisp func
TRANSCRIPT
-
7/28/2019 Visual Lisp Func
1/7
1 Memulaiharus menyertakan perintah :
(vl-load-com)
karena visual lisp adalah ActiveX
2 Jumlah Obyek dalam Selection SetSSLength
Contoh :
(sslength ss )
3 Memilih Obyek(entsel "\n Pilih Obyek :")
jika ada di masukkan dalam variabel
(setq ent(entsel "\n Pilih Obyek :")
4 Menampilkan Dialog Box(Alert " Fungsi Tersebut tidak ada"
)
5 Menggabungkan String(strcat "a" "bout")
6 Memperoleh Nilai Property vla-get-functions correspond to every ActiveX Property, enabling you to
retrieve the value of that Property (for example, vla-get-Color obtains
an Object's Color Property.
contoh :
(vla-get-layer object)
7 Set Nilai Property vla-put-functions correspond to every Property, enabling you to update
the value of the Property (for example, vla-put-Color updates anObjects Color Property.
contoh :
(vla-put-layer object "4")
8 Mengakses Method vla- functions correspond to every ActiveX Method. Use these functions to
invoke the Method (for example, vla-addCircle invokes
the addCircle Method.
-
7/28/2019 Visual Lisp Func
2/7
contoh :
(Vla-offset myline 15.5)
9
Mengecek Apakah Suatu Obyek bisa diUpdate vlax-read-enabled-p Tests whether you can read an Object.
contoh :
(vlax-read-enabled-p myLine)
vlax-write-enabled-pDetermines whether you can modify an Objects
Properties.
contoh
(vlax-write-enabled-p myLine)
vlax-erased-p Checks to see if an Object has been erased. Erased
Objects may still exist in the drawing database.
(vlax-erased-p myLine)
10Mengecek Apakah Suatu Propery atau Method Bisa Diterapkanpada Obyek
Trying to use a Method that does not apply to a specified Object will result in an
error. The same goes for trying to reference a Property that does not apply to an
Object. This will also result in an error. In instances where you are not sure what
applies, use thevlax-method-applicable-pand thevlax-property-
available-pfunctions.
These functions returnTif the Method or Property is available for the Object,
andnilif not.
The syntax forvlax-method-applicable-pis :
(vlax-method-applicable-p object method)
The following command checks to see if the "Copy" Method can be applied to an
Object :
_$ (vlax-method-applicable-p myLine "Copy")
T
The following command determines if the "addBox" Method can be applied to anObject :
_$ (vlax-method-applicable-p myLine "addBox")
nil
Forvlax-property-available-pthe syntax is :
(vlax-property-available-p object property [T])
The following commands determine if Color and Center are properties of
themyLineObject :
-
7/28/2019 Visual Lisp Func
3/7
(vlax-property-available-p myLine "Color")
T
(vlax-property-available-p myLine "Center")
nil
Supplying the optionalTargument tovlax-property-available-pchanges
the meaning of the test. If you supply this argument, the function returns Tonly if
the Object has the Property AND the Property can be modified. If the Object has
no such Property or the Property isRead-Only,vlax-property-available-
preturns nil.
For example, a Circle contains an Area Property, but you cannot update it. If you
check the Property without specifying the optional argument the result isT.
(vlax-property-available-p myCircle "area")
T
If you supply the optional argument, the result is nil :
(vlax-property-available-p myCircle "area" T)
nil
11Menampilakan Semua Property Obyek(vlax-dump-object myline)
(defun C:HaveaDump ( / ent)
(vl-load-com)
(while
(setq ent (entsel))
(vlax-dump-object (vlax-Ename->Vla-Object (car ent))T) );while
(princ)
);defun
(princ)
12Memilih Obyek
(defun selectionlisp1 ( / sset check)
;load the visual lisp extensions
(vl-load-com)
;check for selection
(while
;get the entity and entity name
(setq sset (car (entsel)))
;convert to vl object
-
7/28/2019 Visual Lisp Func
4/7
(setq sset (vlax-ename->vla-object sset))
;check if the entity has a color property
;and it can be updated
(setq check (vlax-property-available-p sset "Color"
T))
;if it can
(if check
;change it's color
(vlax-put-property sset 'Color 4)
);if
);while
(princ)
);defun
(princ)
We select the entity using the standard (entsel) function. We then have to
convert the entity to a VLA Object by using the (vlax-ename->vla-object) function.
Next we check to see if the object first has a color property, and secondly is
updateable using the (vlax-property-available-p) function with it's "T" argument
set. Finally we change it's color property using the (vlax-put-property) function.
Dead easy, hey?
Create Selection sets utilising (ssget) is also quite straightforward.
Have a look at this :
(defun selectionlisp2 ( / sset item ctr check)
;load the visual lisp extensions
(vl-load-com)
;check for selection
(while
;get the selection set
(setq sset (ssget))
;set up the counter
(setq ctr 0)
-
7/28/2019 Visual Lisp Func
5/7
;count the number of entities and loop
(repeat (sslength sset)
;extract the entity name
(setq item (ssname sset ctr))
;convert to vl object
(setq item (vlax-ename->vla-object item))
;check if the entity has a color property
;and it can be updated
(setq check (vlax-property-available-p item
"Color" T))
;if it can
(if check
;change it's color(vlax-put-property item 'Color 6)
);if
;increment the counter
(setq ctr (1+ ctr))
);repeat
);while
(princ)
);defun
(princ)
The only difference here, is that we need to loop through each individual item in
the selection set, converting it to a VLA Object, and then checking and changing
it's properties. Again this is standard AutoLisp with a little bit of VLA thrown in to
confuse you.
To create a selection set using only VLA is a slightly different matter. Here we
need to access the Object Model to reference, create and store our selection set.
Have a look at this :
-
7/28/2019 Visual Lisp Func
6/7
(defun selectionvl ( / ssets acadDocument newsset ctr item)
;load the visual lisp extensions
(vl-load-com)
;retrieve a reference to the documents object
(setq acadDocument (vla-get-activedocument (vlax-get-acad-
object)))
;retrieve a reference to the selection sets object
(setq ssets (vla-get-selectionsets acadDocument))
;add a new selection set
(setq newsset (vla-add ssets "SS1"))
;select your new selection set objects
(vla-selectOnScreen newsset)
;set the counter to zero(setq ctr 0)
;count the number of objects and loop
(repeat (vla-get-count newsset)
;retrieve each object
(setq item (vla-item newsset ctr))
;check if the entity has a color property
;and it can be updated
(setq check (vlax-property-available-p item "Color"
T))
;if it can
(if check
;change it's color
(vlax-put-property item 'Color 5)
);if
;increment the counter
(setq ctr (1+ ctr))
-
7/28/2019 Visual Lisp Func
7/7
);repeat
;delete the selection set
(vla-delete (vla-item ssets "SS1"))
(princ)
);defun
(princ)