How can i get the last object and create a field based on his contents?

How can i get the last object and create a field based on his contents?

Anonymous
Not applicable
1,164 Views
2 Replies
Message 1 of 3

How can i get the last object and create a field based on his contents?

Anonymous
Not applicable

Hi,

 

I'm creating some texts with autolisp and after that trying to create a text field to reference the contents of these texts, but i'm doing it wrong. Can someone help me if it's easy for you?

 

Here i'm sending my dwg with these text fields alright.

 

 (Command "Text" p1 "0.20" "0" "N.1" "")
 

 (setq e1 (ssget "L"))

    ;; This example creates a text object in model space.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
  
    ;; Define the text object
    (setq insertionPoint (vlax-3d-point pm)  
	
	          textString (strcat "%<\\AcObjProp Object(%<\\_ObjId " 
			(itoa (vla-get-ObjectID (vlax-ename->vla-object e1)))
			">%).TextString>%"
		)
          height 0.10)
    
    ;; Create the text object in model space
    (setq modelSpace (vla-get-ModelSpace doc))
    (setq textObj (vla-AddText modelSpace textString insertionPoint height))  
    (vla-ZoomAll acadObj)
0 Likes
1,165 Views
2 Replies
Replies (2)
Message 2 of 3

john.uhden
Mentor
Mentor

I am having trouble understanding your goal.

You used the command function to create text "N.1" at point p1.

Then you went through some mixture of Visual Lisp and scripting to sort of copy the contents to another text object created at point pm.

 

If you had already established pm, then why not just use the command function again using pm instead of p1?

 

Then again, if it works for you and you like excessive code, then you're good.  Some people around here always seem to disdain lengthy code.  I don't care as long as it doesn't take minutes to perform a millisecond operation.

John F. Uhden

0 Likes
Message 3 of 3

DannyNL
Advisor
Advisor

Besides the point your goal John mentions, I'm detecting a problem in your code where you try to pass a selection as an argument where an entity name is needed.

 

 (Command "Text" p1 "0.20" "0" "N.1" "")
 

 (setq e1 (ssget "L"))  ; <-- Remove line

    ;; This example creates a text object in model space.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
  
    ;; Define the text object
    (setq insertionPoint (vlax-3d-point pm)  
	
	          textString (strcat "%<\\AcObjProp Object(%<\\_ObjId " 
			(itoa (vla-get-ObjectID (vlax-ename->vla-object (entlast)))) ; <-- Change selection to last entity
			">%).TextString>%"
		)
          height 0.10)
    
    ;; Create the text object in model space
    (setq modelSpace (vla-get-ModelSpace doc))
    (setq textObj (vla-AddText modelSpace textString insertionPoint height))  
    (vla-ZoomAll acadObj)

of  

0 Likes