Hi,
I've been trying tons of different solutions to solve this problem: insert a block that has an attribute which happens to be the last object id.
This is the best code I tried so far but without any succss.
(defun c:q1()
(command "_.PLINE")
(while (= (getvar "CMDNAMES") "PLINE")
(command pause)
)
(setq objname (entlast))
(setq oad (getvar "attdia"))
(setq orq (getvar "attreq"))
(setq oec (getvar "cmdecho"))
(setvar "attdia" 1)
(setvar "attreq" 0)
(setvar "CMDECHO" 0)
(setq xScale 1)
(setq yScale 1)
(setq rot 0)
(setq at1 "abc")
(setq pt (getpoint "\nSpecify Insertion Point: "))
(command "_.insert" "TROC_PRP" pt xScale yScale rot objname)
(setvar "attdia" oad)
(setvar "attreq" orq)
(setvar "cmdecho" 1)
)
Can you help me?
Kind regards.
Solved! Go to Solution.
Solved by pbejse. Go to Solution.
Solved by pbejse. Go to Solution.
Solved by pbejse. Go to Solution.
Solved by pbejse. Go to Solution.
Try this way
(vlax-invoke (vlax-get (vla-get-ActiveLayout (vla-get-activedocument (vlax-get-acad-object))) 'Block) 'InsertBlock (trans p 1 0) "TROC_PRP" 1 1 1 (- 6.28318531 (getvar 'Viewtwist)) )
Hope this helps
Great! It works!
By the way what does this piece of code do?
(- 6.28318531 (getvar 'Viewtwist))
And, just like the cherry on top, what if I want to specify on screen the rotation?
@Anonymous wrote:Great! It works!
By the way what does this piece of code do?
(- 6.28318531 (getvar 'Viewtwist))And, just like the cherry on top, what if I want to specify on screen the rotation?
prompt for rotation?
Try this
(vlax-invoke (vlax-get (vla-get-ActiveLayout (vla-get-activedocument (vlax-get-acad-object))) 'Block) 'InsertBlock (trans p 1 0) "Elev_Target" 1 1 1 (progn (setq rot (cond ((getangle (strcat "\nEnter Rotation <" (angtos (setq rot (cond ( rot )( 0 ))) ) ">: "))) (rot) ) ) (+ rot (- 6.28318531 (getvar 'Viewtwist))) ) )
HTH
Great! It does the job!
But if I need to use the mouse pointer to determine the block's rotation? I.e. in order to align it with another existent object. Like in a normal block insertion.
Many thanks.
Last but not least...
I inserted the following line:
(setq p (getpoint "\nSpecify Insertion Point: "))
(setq trc (getstring "\nTRC: "))
Down in the program, is this correct?
(vla-put-textstring (car (vlax-invoke blk 'GetAttributes)) tronc (itoa (vla-get-ObjectID objname)))
I want to have the first attribute entered by hand and the second as the pline ObjectID.
@Anonymous wrote:Last but not least...
I inserted the following line:
(setq p (getpoint "\nSpecify Insertion Point: "))
(setq trc (getstring "\nTRC: "))
Down in the program, is this correct?
(vla-put-textstring (car (vlax-invoke blk 'GetAttributes)) tronc (itoa (vla-get-ObjectID objname)))
I want to have the first attribute entered by hand and the second as the pline ObjectID.
That would cause an error
Well....
(defun c:q1 (/ objname p blk trc) (vl-load-com) (prompt "Draw Polyline") (if (and (progn (command "_.PLINE") (while (= (getvar "CMDNAMES") "PLINE") (command pause)) T ) (setq objname (vlax-ename->vla-object (entlast))) (setq p (getpoint "\nSpecify Insertion Point: ")) (setq trc (getstring "\nTRC: "))) (progn (setq blk (vlax-invoke (vlax-get (vla-get-ActiveLayout (vla-get-activedocument (vlax-get-acad-object))) 'Block) 'InsertBlock (trans p 1 0) "Elev_Target" 1 1 1 (progn (setq rot (cond ((getangle p (strcat "\nEnter Rotation <" (angtos (setq rot (cond ( rot )( 0 ))) ) ">: "))) (rot) ) ) (+ rot (- 6.28318531 (getvar 'Viewtwist))) ) ) ) (mapcar '(lambda (l1 l2) (vla-put-textstring l2 l1)) (list trc (itoa (vla-get-ObjectID objname))) (vlax-invoke blk 'GetAttributes)) ) ) (princ) )
HTH
HELP!!!! I Need help!!!!
Afte using for several hours the last code, and exporting all the blocks created and associated info (the pline ObjectID to be precise, I needed to change one of my plines width... AHHHHHHH!!!!!!! ALL PLINES got their ObjectID CHANGED!!!!!
Any ideas?!....
Is it possible to add this block an attribute that relates to the pline ObjectID but in a field way?... 😉 That would be realy nice, when I finished editing the drawing I'd just need to update and that's it... I think...
Thanks in advance.
@Anonymous wrote:HELP!!!! I Need help!!!!
Afte using for several hours the last code, and exporting all the blocks created and associated info (the pline ObjectID to be precise, I needed to change one of my plines width... AHHHHHHH!!!!!!! ALL PLINES got their ObjectID CHANGED!!!!!
Any ideas?!....
Is it possible to add this block an attribute that relates to the pline ObjectID but in a field way?... 😉 That would be realy nice, when I finished editing the drawing I'd just need to update and that's it... I think...
Thanks in advance.
Are you sure the object ID changed? AFAICT Object ID's unique for the lifetime of the database
IF that is the case, i suppose we can write a support code to update the attrib value.
Honestly, I wouldnt know how to assign THE ObjectId to a field code.. Is that even possible? butthen again. i'm no expert with field codes.
What i did before when faced with a similar problem was assign a value <not included on the filed code property of an object> to a named variable and use the value for Field Expression <lispVariable> "%<\\AcVar.17.0 Lisp.varname>%"
and in conjuntion with Xdata as identifier when updating values
Are you absolutely certain about the change in ObjectID ?
Just got it!!!
I changed the ObjectID by the Handle, and now, even if I move, stretch, add vertexes, whatever, it doesn't change!!!!
Thanks anyway.
In the last code Instead of using
(list trc (itoa (vla-get-ObjectID objname)))
I used the following
(list trc (vla-get-handle objname))