Jump to content

To Get and Set the Value of an Object Property (AutoLISP)


Recommended Posts

Posted

Dear coders

 

 

Any of you experience with get and set object properties?

Trying to GET the object property of an block but all is given back is the ename of the block record Not the string that you can see when dumping the properties

 

 

i.e

when dumping the props i see this

 

 

.....

BlockId (type: AcDbObjectId) (RO) = 7ffff9359f0

.....

 

 

When doing

 

 

(getpropertyvalue e1 "BlockId")

 

 

all i get back is

 

 

$ (getpropertyvalue e1 "BlockId")

_$

 

 

When doing entget

 

 

((-1 . ) (0 . "BLOCK_RECORD") (5 . "1F") (102 . "{ACAD_XDICTIONARY") (360 . ) (102 . "}") (330 . ) (100 . "AcDbSymbolTableRecord") (100 . "AcDbBlockTableRecord") (2 . "*Model_Space") (360 . ) (340 . ) (70 . 0) (280 . 1) (281 . 0))

 

 

 

 

I get a sh*t load of info but not the block id i am after

Or am i missing stuff?

Posted

my version 2007 does not have this function

(getpropertyvalue e1 "BlockId")

 

let other active members to assist you..

 

 

FWIW this is example to get "value"..

((lambda (l)
  (vlax-for x (vla-get-blocks (vla-get-ActiveDocument (vlax-get-acad-object)))
    (setq l (cons (cons (vla-get-Name x)(vla-get-[color="blue"]ObjectID[/color] x)) l))
    ) 
  l )
 nil
 )

 

(("BKL" . 2130687768) ("_Oblique" . 2130687736) ("*Paper_Space0" . 2130627944) ("*Paper_Space" . 2130627904) ("*Model_Space" . 2130627832)) 

 

i could be wrong for your BlockId value..

Posted

Following functions are available since AC2012

dumpallproperties

getpropertyvalue

setpropertyvalue

ispropertyreadonly

 

I dont know what OP whant to achive, with ename as string, maybe some more explanation?

btw (how to get ename as string)

(vl-princ-to-string (CAR (ENTSEL)))

Posted

On 2015, I don't have "BlockId" on a block record, but I have a "ObjectID". Vlax-dump say that the value is 43 (RO), and getpropertyvalue returns an ename. Fishy.

 

From your example, the string your dump returns (7ffff9359f0) seems to be the ename you get with getpropertyvalue () but I never saw a program using strings for enames, and as far as i know you cannot "create" an ename from a string either.

 

The functions getpropertyvalue/getpropertyvalue have been created for mac users as a replacement for vlax-get-property/vlax-put-property, but they seem buggy and don't always work. For instance if I use (getpropertyvalue myblkrecord "IsDynamicBlock") it returns; error: ADS request error

 

If you are a windows user, I recommend the Vlisp as follow

(vlax-get-property (vlax-ename->vla-object myblkrecord) "ObjectID"). If I use (vlax-get-property (vlax-ename->vla-object myblkrecord) "IsDynamicBlock") it works and returns :vlax-false.

 

Side note: if a property has (RO) when you dump, it meand it is Read Only, so you can get them but not set them.

Posted

@hanhphuc

@Jef!

Thanks for the code :-D but i cant use the object id as this changes when block has minor change

I need 1 reliable property that i can use to select 1 entity ( the only 1 i can think of is insertion point in combination with ename )

Why the extra check --> because a person can insert multiple blocks of same name with different content so blockname is a nono

I want my routines to be only activex not autolisp but in this case i think i have no choose

Need to convert vla-object to ename and from there get assoc 10 or combine with insertion point as vlax array

 

 

@ziele_o2k Thanks for the code

 

@Jef! Thanks for informning me about the MAC part i forgot about that

Posted

"Need to convert vla-object to ename and from there get assoc 10 or combine with insertion point as vlax array ": vlax-vla-object->ename

 

To get an insertion point: (vlax-get obj 'insertionpoint) or (cdr (assoc 10 (entget ename)))

Posted
(...)

I need 1 reliable property that i can use to select 1 entity

(...)

 

Why you can't use handle?

 

On 2015, I don't have "BlockId" on a block record, but I have a "ObjectID". Vlax-dump say that the value is 43 (RO), and getpropertyvalue returns an ename. Fishy.

 

From your example, the string your dump returns (7ffff9359f0) seems to be the ename you get with getpropertyvalue () but I never saw a program using strings for enames, and as far as i know you cannot "create" an ename from a string either.

 

The functions getpropertyvalue/getpropertyvalue have been created for mac users as a replacement for vlax-get-property/vlax-put-property, but they seem buggy and don't always work. For instance if I use (getpropertyvalue myblkrecord "IsDynamicBlock") it returns; error: ADS request error

 

If you are a windows user, I recommend the Vlisp as follow

(vlax-get-property (vlax-ename->vla-object myblkrecord) "ObjectID"). If I use (vlax-get-property (vlax-ename->vla-object myblkrecord) "IsDynamicBlock") it works and returns :vlax-false.

 

Side note: if a property has (RO) when you dump, it meand it is Read Only, so you can get them but not set them.

To see what properties you can use with get/set propertyvalue you should use dumpallproperties instead of Vlax-dump. Yes it was for mac users, but this is not replacment 1:1 for vlax-get/vlax-set property.

get/set propertyvalue gives much more possibilities.

I can give some examples if you whant.

Posted

You're welcome!

Thanks for the code :-D but i cant use the object id as this changes when block has minor change

I need 1 reliable property that i can use to select 1 entity ( the only 1 i can think of is insertion point in combination with ename )

Why the extra check --> because a person can insert multiple blocks of same name with different content so blockname is a nono

 

It is quite hard to make suggestions blindly without knowing exactly what you are trying to achieve and what you have done so far, but some points that might be worth mentioning:

Block records and block insertions are 2 different things. The block record is the block definition, what you see when you use block edit or refedit. You cannot "select" a block definition. When a user "select a block" he actually select an insert.

Different Inserts of a given block definition will always have the same content, unless the block is dynamic. If the block is dynamic, the insert's name become anonymous (ie:*232), so you need to check its property "EffectiveName" to get the name of the corresponding block definition. You can use one of the following

(vlax-get-property (vlax-ename->vla-object (car(entsel))) "EffectiveName") or

(vla-get-EffectiveName (vlax-ename->vla-object (car(entsel))) )

Some things are done more easily in lisp, some in Visual lisp or active-x. Don't limit yourself to one language just for the sake of it... more options more fun :)

 

Feel free to post your code for suggestions.

Cheers

 

edit:

@ziele

To see what properties you can use with get/set propertyvalue you should use dumpallproperties instead of Vlax-dump. Yes it was for mac users, but this is not replacment 1:1 for vlax-get/vlax-set property.

get/set propertyvalue gives much more possibilities.

I can give some examples if you whant.

IsDynamicBlock doesn'T work in 2015... unless it is mac only? I would be very curious to see on which facts you based that "get/set propertyvalue gives much more possibilities.". I'm always opened minded for learning new things! :)

Posted
You're welcome!

 

It is quite hard to make suggestions blindly without knowing exactly what you are trying to achieve and what you have done so far, but some points that might be worth mentioning:

 

Well...lol all i wanted is getting the blockid using the getpropertyvalue which in the end seems to be the str of the ename.

Cant really use it but have an answer that i can work with :-D

Posted

@ziele

IsDynamicBlock doesn'T work in 2015... unless it is mac only? I would be very curious to see on which facts you based that "get/set propertyvalue gives much more possibilities.". I'm always opened minded for learning new things! :)

 

As 1st example from other forum - try to delete objects from attached .dwg only with VanillaLisp/VisualLisp :)

More examples later and also I will check IsDynamicBlock property.

del_obj.dwg

Posted

@DGRL you are welcome

 

@Jef! @Ziela

Thanks for the info, i think i've seen in Lee Mac dynamic block function but no luck

for AC2007 on old pc. will upgrade soon

 

from Ronjonp's example above

(vlax-get obj 'insertionpoint) 
(getpropertyvalue obj "insertionpoint")

same?

Posted
As 1st example from other forum - try to delete objects from attached .dwg only with VanillaLisp/VisualLisp :)

More examples later and also I will check IsDynamicBlock property.

 

Sweet! Anonymous locked layers. I like them as appetizer before breakfast. This is listed as an impossible task in another forum? No problem for me in vanilla... and vanilla goes well with coffee. Café vanille française. Hmmm. :)

(defun c:breakfast ( / sset sspos e laydef)
 (if (setq sset (ssget "_X" '((410 . "Model"))))
     (progn
       (setq sspos (sslength sset))
       (while (setq e (ssname sset (setq sspos (1- sspos))))
              (if (= 4 (logand 4 (cdr (assoc 70 (setq laydef (entget(tblobjname "layer" (cdr (assoc 8 (entget e))))))))))
                  (entmod (subst (cons 70 (boole 6 4 (cdr (assoc 70 laydef)))) (assoc 70 laydef) laydef))
              )
              (entdel e)
       )
     )
 )
 (princ)
)

Next! :P

 

from Ronjonp's example above

(vlax-get obj 'insertionpoint) 
(getpropertyvalue obj "insertionpoint")

same?

Yes.... Always many ways to skin a cat as they say :)

Posted
Sweet! Anonymous locked layers. I like them as appetizer before breakfast. This is listed as an impossible task in another forum? No problem for me in vanilla... and vanilla goes well with coffee. Café vanille française. Hmmm. :)

(...)

Next! :P

Yes.... Always many ways to skin a cat as they say :)

That was listed as impossible to do without any kind of coding.

 

Now to next examples:

Here is code from gile to unformat mtext

(setpropertyvalue mtext "Contents" (getpropertyvalue mtext "Text"))

To do this with lisp you have to write a lot more lines of code :)

Anyway. Where "new" functions are useful to me? When I'm working with advance steel. AS has it's own elements like beams, plates, special parts, etc.

Without dumpallproperties/getpropertyvalue I can't interact with these elements by lisp.

Example of dump advance steel beam element:

; IAcadEntity: Interfejs AutoCAD Entity
; Wartości właściwości:
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00007ff672f370f8>
;   Document (RO) = #<VLA-OBJECT IAcadDocument 000002336a0fec68>
;   EntityTransparency = "JakWarstwa"
;   Handle (RO) = "2E0"
;   HasExtensionDictionary (RO) = 0
;   Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 000002334c108548>
;   Layer = "AS_Belki"
;   Linetype = "ByLayer"
;   LinetypeScale = 20.0
;   Lineweight = -1
;   Material = "ByLayer"
;   ObjectID (RO) = 42
;   ObjectName (RO) = "AstBeamRepr"
;   OwnerID (RO) = 43
;   PlotStyleName = "ByLayer"
;   TrueColor = #<VLA-OBJECT IAcadAcCmColor 000002334c109620>
;   Visible = -1
; Obsługiwane metody:
;   ArrayPolar (3)
;   ArrayRectangular (6)
;   Copy ()
;   Delete ()
;   GetBoundingBox (2)
;   GetExtensionDictionary ()
;   GetXData (3)
;   Highlight (1)
;   IntersectWith (2)
;   Mirror (2)
;   Mirror3D (3)
;   Move (2)
;   Rotate (2)
;   Rotate3D (3)
;   ScaleEntity (2)
;   SetXData (2)
;   TransformBy (1)
;   Update ()

and dumpallproperties for same element:

Begin dumping object (class: AstBeamRepr)
Annotative (type: bool)  (LocalName: Opisowy) = Failed to get value
AnnotativeScale (type: AcString)  (RO)  (LocalName: Skala opisu) = Failed to get value
Atrybut Użytkownika 1 (type: AcString)  (RO) = -
Atrybut Użytkownika 10 (type: AcString)  (RO) = -
Atrybut Użytkownika 2 (type: AcString)  (RO) = -
Atrybut Użytkownika 3 (type: AcString)  (RO) = -
Atrybut Użytkownika 4 (type: AcString)  (RO) = -
Atrybut Użytkownika 5 (type: AcString)  (RO) = -
Atrybut Użytkownika 6 (type: AcString)  (RO) = -
Atrybut Użytkownika 7 (type: AcString)  (RO) = -
Atrybut Użytkownika 8 (type: AcString)  (RO) = -
Atrybut Użytkownika 9 (type: AcString)  (RO) = -
BlockId (type: AcDbObjectId)  (RO) = 233510f99f0
CastShadows (type: bool) = 1
Ciężar (type: AcString)  (RO) = 21.61
ClassName (type: AcString)  (RO) =
CollisionType (type: AcDb::CollisionType)  (RO) = 1
Color (type: AcCmColor)  (LocalName: Kolor) = JAKWARSTWA
Data dostawy (type: AcString)  (RO) = -
Data wysyłki (type: AcString)  (RO) = -
Dokładna waga (type: AcString)  (RO) = 21.61
Dostawca (type: AcString)  (RO) = -
Etap (type: AcString)  (RO) = -
ExtensionDictionary (type: AcDbObjectId)  (RO) = 0
Funkcja (type: AcString)  (RO) = Brak
Handle (type: AcDbHandle)  (RO) = 2e0
HasFields (type: bool)  (RO) = 0
HasSaveVersionOverride (type: bool) = 0
Hyperlinks (type: AcDbHyperlink*)
IsA (type: AcRxClass*)  (RO) = AstBeamRepr
IsAProxy (type: bool)  (RO) = 0
IsCancelling (type: bool)  (RO) = 0
IsEraseStatusToggled (type: bool)  (RO) = 0
IsErased (type: bool)  (RO) = 0
IsModified (type: bool)  (RO) = 0
IsModifiedGraphics (type: bool)  (RO) = 0
IsModifiedXData (type: bool)  (RO) = 0
IsNewObject (type: bool)  (RO) = 0
IsNotifyEnabled (type: bool)  (RO) = 0
IsNotifying (type: bool)  (RO) = 0
IsObjectIdsInFlux (type: bool)  (RO) = 0
IsPersistent (type: bool)  (RO) = 1
IsPlanar (type: bool)  (RO) = 0
IsReadEnabled (type: bool)  (RO) = 1
IsReallyClosing (type: bool)  (RO) = 1
IsTransactionResident (type: bool)  (RO) = 0
IsUndoing (type: bool)  (RO) = 0
IsWriteEnabled (type: bool)  (RO) = 0
Klasa konstrukcji (type: AcString)  (RO) = Brak
Klasa profilu (type: AcString)  (RO) = HEA DIN 1025-3
Klasa szczegółów (type: AcString)  (RO) = Brak
Kod stanu zatwierdzenia (type: AcString)  (RO) = -
Komentarz do zatwierdzenia (type: AcString)  (RO) = -
L przekrój [%s]: (type: AcString)  (RO) = 511
L system [%s]: (type: AcString)  (RO) = 511
LayerId (type: AcDbObjectId)  (LocalName: Warstwa) = 233510f9c50
LineWeight (type: AcDb::LineWeight)  (LocalName: Szerokość linii) = -1
LinetypeId (type: AcDbObjectId)  (LocalName: Rodzaj linii) = 233510f9950
LinetypeScale (type: double)  (LocalName: Skala rodzaju linii) = 20.000000
LocalizedName (type: AcString)  (RO) =
MaterialId (type: AcDbObjectId)  (LocalName: Materiał) = 233510f9ec0
Materiał (type: AcString)  (RO) = S235JR
MergeStyle (type: AcDb::DuplicateRecordCloning)  (RO) = 1
Nazwa (type: AcString)  (RO) = HEA200
Nr produktu (type: AcString)  (RO) = -
Numer elementu pozycji (type: AcString)  (RO) = Niezdefiniowany
Numer elementu wysyłkowego (type: AcString)  (RO) = Niezdefiniowany
Numer polecenia zakupu (type: AcString)  (RO) = -
Numer wytopu (type: AcString)  (RO) = -
Numer zapotrzebowania (type: AcString)  (RO) = -
Numer ładunku (type: AcString)  (RO) = -
ObjectId (type: AcDbObjectId)  (RO) = 233510f1e00
OwnerId (type: AcDbObjectId)  (RO) = 233510f99f0
Oznaczenie (type: AcString)  (RO) = -
PlotStyleName (type: AcString)  (RO)  (LocalName: Styl wydruku) = JakKolor
Powłoka (type: AcString)  (RO) = Brak
Predefiniowane oznacz. (type: AcString)  (RO) = -
Profile (type: AcString)  (RO) = HEA200
Przewoźnik (type: AcString)  (RO) = -
ReceiveShadows (type: bool) = 1
ShadowDisplay (type: AcDb::ShadowFlags)  (LocalName: Wyświetlanie cieni) = 0
Skróć na rys. (type: AcString)  (RO) = 0
Stan zatwierdzenia (type: AcString)  (RO) = Nie ustawiono
Stanowisko produkcyjne (type: AcString)  (RO) = -
Transparency (type: AcCmTransparency)  (LocalName: Przezroczystość) = 0
Typ (type: AcString)  (RO) = Belka prosta
Ufność (type: AcString)  (RO) = Brak
Visible (type: AcDb::Visibility) = 0
Wstępna numeracja (type: AcString)  (RO) = Niezdefiniowany
End object dump

As you can see I have access to read (most of them are RO) much more properties.

 

Last thing. New object from AC2017 Centerline and Centermark. It is much easier to handle them with get/setproperty than with old school visual/vanilla lisp.

Posted
That was listed as impossible to do without any kind of coding.

Awesome! 8)

Here is code from gile to unformat mtext

(setpropertyvalue mtext "Contents" (getpropertyvalue mtext "Text"))

To do this with lisp you have to write a lot more lines of code

Neat! Yeah, I remember having seen a routine "with lisp" to do that, it was very long and complex, and had many revisions. Maybe my memory is playing with me but I think it was Lee's. I don't see Getpropertyvalue as "another kind of coding" tho, and contrary to what you seem to think (referring to "To do this with lisp..."), Getproperty is still an AutoLISP function. :)

 

I do see that it has some differences with vlax-get/set, and that for the text property it definitely has an edge, but some limitations as well as per the first property I happened to test it with (IsDynamicBlock). Without in depth analysis I have a hard time being convinced that it has access to a lot of properties that are not available by other means. I have to admit that it's definitely something worthy of investigating further. We both learned something new here! :thumbsup:

 

As you can see I have access to read (most of them are RO) much more properties.
My feeling is that it might be xdata, ldata or xrecord. I'd be curious to take a look at a drawing with one of these steel members... Could you please upload one?

 

Nice 1 @Jef!

Thanks DGRL! :)

Posted
Awesome! 8)

 

Neat! Yeah, I remember having seen a routine "with lisp" to do that, it was very long and complex, and had many revisions. Maybe my memory is playing with me but I think it was Lee's.

 

There is a lot of lisps to strip mtext and one of them (most perfected in my opinion) is Lee's code ofc 8)

 

I don't see Getpropertyvalue as "another kind of coding" tho, and contrary to what you seem to think (referring to "To do this with lisp..."), Getproperty is still an AutoLISP function. :)

 

unfortunately not for me, because I'm always testing my lisps on Autocad's derivative programs, which don't have this functions implemented.

 

I do see that it has some differences with vlax-get/set, and that for the text property it definitely has an edge, but some limitations as well as per the first property I happened to test it with (IsDynamicBlock). Without in depth analysis I have a hard time being convinced that it has access to a lot of properties that are not available by other means. I have to admit that it's definitely something worthy of investigating further. We both learned something new here! :thumbsup:

 

I have to investigate IsDynamicBlock prop. Anyway, that is also my opinion, it's good to know these functions but without them we have more fun :)

 

My feeling is that it might be xdata, ldata or xrecord. I'd be curious to take a look at a drawing with one of these steel members... Could you please upload one?

 

Yep, but you must wait until Tuesday or you can look at autodesk advance steel forum, from where you can download some files.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...