Save object names to use anytime

Save object names to use anytime

Anonymous
Not applicable
1,377 Views
3 Replies
Message 1 of 4

Save object names to use anytime

Anonymous
Not applicable

My first question is: When I have an object, as a block or a line, in Autocad. Every time I open this drawing, the Vla object name will still be the same?

 

If it is, I would like to save some vla object names, so another time I open Autocad, I can acess the object though its vla name. Do you now thew best way to do that? Save as a text for example.

0 Likes
Accepted solutions (1)
1,378 Views
3 Replies
Replies (3)
Message 2 of 4

Kent1Cooper
Consultant
Consultant
Accepted solution

Welcome to these Forums!

 

No, the conversion of an entity into a VLA object does not survive closing the drawing and getting back in.  Even the entity name of an object can change from one drawing session to another.

 

The way you would do that is by saving the entity's Handle, which does not change, no matter what.  It's in the (assoc 5) entry in entity data:

 

(setq EntityHandle (cdr (assoc 5 (entget (car (entsel "\nSelect object to get its Handle: "))))))

 

and then you can get the entity name back for whatever purpose with the (handent) function:

 

(handent EntityHandle)

 

You can save such things externally to the drawing, with a few different approaches, such as by way of environment variables [look into the (setenv) and (getenv) AutoLisp functions], in which case you should give the names of those an element relating them to the specific drawing, because the same Handle could exist in other drawings, identifying some different entity.

 

Another way would be to write them out to a plain text file or a .csv spreadsheet file, using the (write-line) function to put them there and (read-line) to get them out.  Again, name such a file with something specific to the drawing you're in.

 

You could put Handles into Text or Mtext parked off to the side somewhere, which would keep everything within the drawing file itself, not requiring anything external as the above options do [which means, for example, you could send a drawing to someone else, and it would have all that information].

 

I'm sure there are other ways....

Kent Cooper, AIA
Message 3 of 4

john.uhden
Mentor
Mentor

To add to what @Kent1Cooper astutely pointed out, you could store the handles in a dictionary of your own inside the drawing.

You could also use extended entity date (aka "xdata") though that requires registering an application, which if used excessively and uniquely will slow down your drawing open to the speed of a paralyzed sloth.

John F. Uhden

Message 4 of 4

pbejse
Mentor
Mentor

@john.uhden wrote:

... store the handles in a dictionary of your own inside the drawing.

You could also use extended entity date (aka "xdata")...



or LDATA

 

;__________________________________________________________________________________________________________
;
; This Function stores variable values (strings, integers, reals, lists... not vla-objects or entitynames)
; Written By Peter Jamtgaard copyright 2014 all rights reserved
;_________________________________________________________________________________________________________
;
; Syntax: (VariableStore (list 'A 'B 'C)); Where A, B and C are variables you wish to store for example
;_________________________________________________________________________________________________________


(defun VariableStore (lstOfSymbols / lstOfSublists)
 (and
  lstOfSymbols
  (setq lstOfSublists (mapcar '(lambda (X)(list X (eval (eval X)))) lstOfSymbols))
  (vlax-ldata-put (vla-item (vla-get-layers 
                             (vla-get-activedocument 
                              (vlax-get-acad-object))) "0") 
                  "Variables" 
                   lstOfSublists
  )
 )
)

;_________________________________________________________________________________________________________
;
; Syntax (VariableReStore)
;_________________________________________________________________________________________________________

(defun VariableReStore (/ lstOfSublists objLayerZero)
 (and
  (setq objLayerZero (vla-item
                      (vla-get-layers 
                       (vla-get-activedocument 
                        (vlax-get-acad-object))) "0")
  )
  (setq lstOfSublists (vlax-ldata-get objLayerZero "Variables" ))
  (mapcar '(lambda (X)(set (car X) (cadr X))) lstOfSublists) 
  ; (vlax-ldata-put objLayerZero "Variables" nil); <- Can delete ldata using this command if desired.
 )
)

(vl-load-com)