Jump to content
samifox

Getting help from the Autocad ActiveX and VBA reference

Recommended Posts

samifox

Hi

 

in Autolisp when i want information about a function i just need to highlight it and press ctrl+F1 and get help, in visual lisp, when doing the same thing i get a different help system : Autocad ActiveX and VBA reference which is useless for me, i dont understand and cant make any analogues to autolisp help.

 

can someone analogues it to autollisp help?

for example, vla-put-layer?

 

in the activeX help :

 

Signature

 

object.Layer

 

object

 

All Drawing objects, AttributeReference, Group

The object this property applies to.

 

Layer

 

String; read-write (write-only for the Group object)

The name of the layer.

 

Remarks

 

All objects have an associated layer. The document always contains at least one layer (layer 0). As with linetypes, you can specify a layer for an object. If you don't specify a layer, the current active layer is used for a new object. If a layer is specified for an object, the current active layer is ignored. Use the ActiveLayer property to set or query the current active layer.

 

Each layer has associated properties that can be set and queried through the Layer object.

 

 

 

please help!

Shay

Share this post


Link to post
Share on other sites
Lee Mac

In ActiveX, when manipulating an Object or Collection you have two types of functions: Properties & Methods. To list the available properties & methods for a VLA-Object, you can use the vlax-dump-object function, as this function demonstrates.

 

ActiveX Properties

 

For every ActiveX Property associated with a VLA-Object, there are two functions generated by the type library for the AutoCAD Object Model for retrieving and modifying the property value.

Retrieving a Property Value

(vla-get-<Property-Of-Object> <VLA-Object>)
 

Will return the current value of the given property, for example:

(vla-get-layer <VLA-Object>)
 

Will return the value of the Layer property of a supplied VLA-Object, i.e. the name of the layer assigned to the object. If the object does not have the ActiveX Layer property, the function will error with an 'unknown name' error.

 

Modifying a Property Value

(vla-put-<Property-Of-Object> <VLA-Object> <Property-Value>)
 

This function will set the specified ActiveX property of the VLA-Object to the value provided.

 

However, as noted above, these functions are 'convenience' functions, generated by the AutoCAD type library.

 

In general, we can retrieve & modify (unless read-only) the ActiveX properties of any VLA-Object, (whether within the AutoCAD Object Model (children of the AutoCAD Application Object [vlax-get-acad-object]), or derived from another Object Model, such as the Excel Application) using the following functions:

(vlax-get-property <VLA-Object> <Property-Of-Object>)

and

(vlax-put-property <VLA-Object> <Property-Of-Object> <Property-Value>)
 

More information about the AutoCAD Object Model and the differences between these functions may be found in an earlier post of mine here.

 

The ActiveX Help Documentation (found in the acadauto.chm local help file, or online here) for these properties will have the following format (Layer property used as an example below):

 

ActiveX & VBA Reference said:

Signature

 

object.Layer

 

object

All Drawing objects, AttributeReference, Group

The object or objects this property applies to.

 

Layer

String; read-write (write-only for the Group object)

The name of the layer.

 

Here, object is the VLA-Object to which the ActiveX Property applies - i.e. the object(s) that have this particular ActiveX Property.

 

.Layer is the name of the ActiveX Property in question; since AutoLISP is case-insensitive, this property name is also case-insensitive, however, such properties are commonly case-sensitive in other programming languages.

 

So, with the above example, we see that the Layer property applies to all drawing objects, including Attribute References & Groups.

 

We also see that the value of the Layer property has a String data-type and that the value of this property indicates the name of the layer assigned to an object.

 

Hence, in practice we can retrieve the value of this property in the following manner:

_$ (setq obj (vlax-ename->vla-object (car (entsel))))
#<VLA-OBJECT IAcadLine 21c326bc>
_$ (vla-get-layer obj)
"0"
_$ (vlax-get-property obj 'layer)
"0"
_$ (vlax-get-property obj "layer")
"0"
_$ (vlax-get obj "layer")
"0"
 

And we can modify the property in a similar way:

_$ (setq obj (vlax-ename->vla-object (car (entsel))))
#<VLA-OBJECT IAcadLine 21c326bc>
_$ (vla-get-layer obj)
"0"
_$ (vla-put-layer obj "MyLayer")
nil
_$ (vla-get-layer obj)
"MyLayer"
 

ActiveX Methods

 

ActiveX Methods may also be used to manipulate VLA-Objects. Whereas an object has inherent Properties each of which holding a single value, ActiveX Methods may require several parameters to execute an operation on a VLA-Object.

 

Similar to ActiveX Properties, each ActiveX Method pertaining to a method within the AutoCAD Object Model also has a 'convenience' function automatically generated by the AutoCAD type library, which takes the following format:

(vla-<Method-Of-Object> <VLA-Object> <Arg1> ... <ArgN>)

Again, we can invoke the method of any VLA-Object (derived from any Object Model) using the generalised function:

(vlax-invoke-method <VLA-Object> <Method-Of-Object> <Arg1> ... <ArgN>)

As noted in my earlier link, there are also the undocumented functions vlax-get/vlax-put/vlax-invoke which will operate with native AutoLISP data types as opposed to the Safearray & Variant data-types as used by Visual LISP; though, to avoid a digression, more information about these functions may be found here.

 

Using the move method as an example, the documentation for ActiveX Methods use the following format:

ActiveX & VBA Reference said:

Signature

 

object.Move Point1, Point2

 

object

All Drawing Objects, AttributeReference

The object or objects this method applies to.

 

Point1

Variant (three-element array of doubles); input-only

The 3D WCS coordinates specifying the first point of the move vector.

 

Point2

Variant (three-element array of doubles); input-only

The 3D WCS coordinates specifying the second point of the move vector.

 

Again, object is the VLA-Object on which the ActiveX Method may operate; in this case we can invoke the move method on all drawing objects, including Attribute References.

 

Then, Point1 & Point2 are the input parameters required by the method (the parameters of some methods may be optional - this will be noted beside the parameter in the reference).

 

From the reference, we can see that these parameters are the first and second point of the move vector, or, in other words, the base point and displacement for the move operation.

 

We can also see that these parameters are of Variant data-type (more information about Safearrays & Variants may be found in the Developer Documentation); with the Variant containing a 3D point expressed relative to the World Coordinate System (WCS).

 

For 3D point variants, as required by such methods, Visual LISP provides another 'convenience' function in the form of the vlax-3D-point function. This function will accept two or three numerical parameters as X, Y & optionally Z coordinates, or a list of coordinates and will return a Variant containing a one-dimensional Safearray of Double type containing the three coordinate values.

 

Hence, we can call the move method in the following way:

(vla-move <VLA-Object> (vlax-3D-point <Point1>) (vlax-3D-point <Point2>))
 

Or, using the vlax-invoke-method function:

(vlax-invoke-method <VLA-Object> 'move (vlax-3D-point <Point1>) (vlax-3D-point <Point2>))
 

I hope this clarifies the format of the ActiveX & VBA Reference.

Edited by Lee Mac

Share this post


Link to post
Share on other sites
asos2000
In ActiveX, when manipulating an Object or Collection you have two types of functions: Properties & Methods.

...

Thankx LEE as usual pefect

Share this post


Link to post
Share on other sites
Lee Mac
Thankx LEE as usual pefect

 

Thank you asos, I'm glad it helps. :)

Share this post


Link to post
Share on other sites
samifox

Thank you LEE. i bet you are really Quantum Mechanic :D

Share this post


Link to post
Share on other sites
Lee Mac
Thank you LEE. i bet you are really Quantum Mechanic :D

 

You're welcome Shay - I hope my explanation was clear. :beer:

Share this post


Link to post
Share on other sites
samifox

please delete admin

Edited by samifox

Share this post


Link to post
Share on other sites
samifox

all of those forms a syntax alternative only?

(vlax-invoke-method <VLA-Object> 'move (vlax-3D-point <Point1>) (vlax-3D-point <Point2>))
(vla-put-<Property-Of-Object> <VLA-Object> <Property-Value>)
(vlax-put-property <VLA-Object> <Property-Of-Object> <Property-Value>)

Share this post


Link to post
Share on other sites
Lee Mac
all of those forms a syntax alternative only?

(vlax-invoke-method <VLA-Object> 'move (vlax-3D-point <Point1>) (vlax-3D-point <Point2>))
(vla-put-<Property-Of-Object> <VLA-Object> <Property-Value>)
(vlax-put-property <VLA-Object> <Property-Of-Object> <Property-Value>)

 

You are comparing methods with properties.

 

With regards to the difference between:

([color=blue]vla-put-[/color][color=darkred]<Property-Of-Object>[/color] [color=green]<VLA-Object>[/color] [color=red]<Property-Value>[/color])
([color=blue]vlax-put-property[/color] [color=green]<VLA-Object>[/color] [color=darkred]<Property-Of-Object>[/color] [color=red]<Property-Value>[/color])

(vla-put-) is a binding that is resolved at compilation time and is undefined unless the relevant type library has been imported for the ActiveX object model referenced by the property (note that the type library for the AutoCAD object model is imported & registered automatically); whereas (vlax-put-property) is a binding resolved during run-time and consequently will be marginally slower to evaluate.

 

The second form is particularly useful when interfacing with an ActiveX object model other than the AutoCAD object model (such as the Excel.Application object model, or perhaps a AutoCAD Vertical), and you either don't have access to the relevant type library or don't want to import it. To provide a quick example of importing a type library targeting another object model, see this post in which I am importing the type library for the FSO.

Share this post


Link to post
Share on other sites
samifox

Ok, so me know if i understand it correct.

 

Visual Lisp maps all aspects of AutoCAD in hierarchical manner called “Object Model” . ActiveX are libraries of properties and methods binded to those objects in the Object Model tree, whenever an object is accessed via the Object Model it can uses ActiveX methods to get and set values.

 

Accessing Autocad Object Model

Access the objects within the Object Model is made by calling all objects residing on the path of the desired object starting with the Application object which is the root object.

For example , getiing pointer to the active Document object

(setq acadpp (vlax-get-acad-object))
(setq acdoc (vla-get-ActiveDocument acadpp))

 

how can i retrieve a collection and add or delete an item? for example i want to add a text style to the active document, how can it be done?

Share this post


Link to post
Share on other sites
Lee Mac
Visual Lisp maps all aspects of AutoCAD in hierarchical manner called “Object Model” . ActiveX are libraries of properties and methods binded to those objects in the Object Model tree, whenever an object is accessed via the Object Model it can uses ActiveX methods to get and set values.

 

Yes - the ActiveX component of Visual LISP (ActiveX is just one component of Visual LISP - there are other groups of Visual LISP functions which do not rely on ActiveX technology and hence do not require the use of vl-load-com prior to use) allows interfacing with the AutoCAD Object Model. ActiveX itself falls under the umbrella of the MS Component Object Model (COM).

 

...how can I retrieve a collection and add or delete an item? for example i want to add a text style to the active document, how can it be done?

 

Accessing the Text Styles collection:

(vla-get-textstyles (vla-get-activedocument (vlax-get-acad-object)))

Adding a new Text Style to the collection:

(vla-add (vla-get-textstyles (vla-get-activedocument (vlax-get-acad-object))) "My TextStyle")

A map of the AutoCAD Object Model may be found here or in the acadauto.chm local help file.

Share this post


Link to post
Share on other sites
samifox

and now how can i control the properties of "My TestStyle"?

how can i rerive a list of the collection membersd

 

Thanks LEE

Shay

Share this post


Link to post
Share on other sites
Lee Mac
and now how can i control the properties of "My TestStyle"?

 

By manipulating the values of the various ActiveX Properties held by the TextStyle object, as described earlier in this thread.

The list of available ActiveX Properties (and Methods) for any VLA-Object can be retrieved using the vlax-dump-object function as described earlier in the thread, and such Properties are also listed in the ActiveX & VBA Documentation.

 

how can i rerive a list of the collection members

 

Using either the vlax-for or vlax-map-collection functions to iterate over all items in the collection and construct a list containing each item encountered. An example of such a function can be found in my Collection Functions.

Share this post


Link to post
Share on other sites
samifox

hi

when sending Boolean vla function i use vlax-true and vlax-false. it not recognized by the IDE and yell an error.

 

what are the right values?

 

Thanks

Shay

Share this post


Link to post
Share on other sites
Lee Mac

:vlax-true / :vlax-false

Share this post


Link to post
Share on other sites
samifox
:vlax-true / :vlax-false

 

Thanks LEE

 

is there a way to access a VLA-object without first extracting it from a collection?

 

and why this code aint working? i tried to lock all layers in the collection

 

(vl-load-com)

(setq acadObject (vlax-get-acad-object))
(setq acadDocument (vla-get-activedocument acadObject))
(setq acadLayers (vla-get-layers acadDocument))
(vlax-map-collection acadLayers 'vla-put-lock :vlax-true)

Share this post


Link to post
Share on other sites
Lee Mac
and why this code aint working? i tried to lock all layers in the collection

 

(vl-load-com)

(setq acadObject (vlax-get-acad-object))
(setq acadDocument (vla-get-activedocument acadObject))
(setq acadLayers (vla-get-layers acadDocument))
(vlax-map-collection acadLayers 'vla-put-lock :vlax-true)

 

Note from the documentation that the vlax-map-collection function requires two arguments: the collection on which the function will be 'mapped', and a function to be 'mapped' across the collection (analogous to how mapcar 'maps' (evaluates) a function across supplied list(s)).

 

In your code, you are supplying the vlax-map-collection function with three arguments: the Layers Collection, the vla-put-lock function and the constant :vlax-true.

 

Consider instead the following code:

(vlax-map-collection (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
  '(lambda ( layer ) (vla-put-lock layer :vlax-true))
)

Share this post


Link to post
Share on other sites
samifox

is there a way to access a VLA-object without first extracting it from a collection?

 

 

 

Thanks

Share this post


Link to post
Share on other sites
Lee Mac
is there a way to access a VLA-object without first extracting it from a collection?

 

What VLA-Object are you attempting to access?

Share this post


Link to post
Share on other sites
samifox

for example , a specific layer without extracting it out of its collection

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...