Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem inserting blocks with attributes

36 REPLIES 36
SOLVED
Reply
Message 1 of 37
Anonymous
2020 Views, 36 Replies

Problem inserting blocks with attributes

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.

36 REPLIES 36
Message 21 of 37
pbejse
in reply to: Anonymous

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

 

Message 22 of 37
Anonymous
in reply to: pbejse

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?

Message 23 of 37
pbejse
in reply to: Anonymous


@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?

Message 24 of 37
Anonymous
in reply to: pbejse

Exactly!

Message 25 of 37
pbejse
in reply to: Anonymous

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

 

Message 26 of 37
Anonymous
in reply to: pbejse

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.

Message 27 of 37
pbejse
in reply to: Anonymous

add p

 

((getangle p
          (strcat "\nEnter Rotation <"

 

 

Message 28 of 37
Anonymous
in reply to: pbejse

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.

Message 29 of 37
pbejse
in reply to: Anonymous


@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

 

Message 30 of 37
Anonymous
in reply to: pbejse

Fantastic!!!

Thanks a lot!!!!

 

Message 31 of 37
pbejse
in reply to: Anonymous


@Anonymous wrote:

Fantastic!!!

Thanks a lot!!!!

 


You;re welcome.

 

Glad I could help

Message 32 of 37
Anonymous
in reply to: pbejse

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.

Message 33 of 37
pbejse
in reply to: Anonymous


@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 ?


 

Message 34 of 37
Anonymous
in reply to: pbejse

Smiley Happy

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.

Message 35 of 37
stevor
in reply to: Anonymous

So how did you change that ObjectID?

S
Message 36 of 37
Anonymous
in reply to: stevor

In the last code Instead of using 

 

(list trc (itoa (vla-get-ObjectID objname)))

I used the following

 

(list trc (vla-get-handle objname))
Message 37 of 37
stevor
in reply to: Anonymous

Thanks' for clarifying what was canged:

the value of the variable trc was changed.

S

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost