Change Attribute Value with user input

Change Attribute Value with user input

Anonymous
Not applicable
1,265 Views
9 Replies
Message 1 of 10

Change Attribute Value with user input

Anonymous
Not applicable

Hello everyone, 

I am looking for a lisp that will take my block with 5 different Attributes and and go through them and ask the user what the values should be. There is A LOT of stuff out there on attributes and i cant seem to find what i need even to write it myself. 

My block name is DXF TAG

The attributes are as follows:

JOBNAME

JOBNUMBER

PRODUCT

VIEW

QUANTITY

The routine i am working on will insert this block from another dwg and ask the user to pick an insertion point. 

after the block has been inserted it will go through the list updating the attributes. After that it will burst the block in order to keep the updated text.

There might be many more ways to do this but this is the only way that i can think of.  I am open to any ideas if anyone has any input.

 

Thanks for all the help!

0 Likes
1,266 Views
9 Replies
Replies (9)
Message 2 of 10

dbhunia
Advisor
Advisor

Try this....Roughly coded 

 

(defun c:IBB (/ JOBNA JOBNU PDT VIEW QTY Areq ss)
(vl-load-com)
(setq Areq (getvar 'ATTREQ))
(setvar 'ATTREQ 0)
(setvar 'CMDECHO 0)
(setq ss (ssadd))
(if (= (setq JOBNA (getstring T "\nEnter JOBNAME: ")) "") (setq JOBNA " "))
(if (= (setq JOBNU (getstring T "\nEnter JOBNUMBER: ")) "") (setq JOBNU " "))
(if (= (setq PDT (getstring T "\nEnter PRODUCT: ")) "") (setq PDT " "))
(if (= (setq VIEW (getstring T "\nEnter VIEW: ")) "") (setq VIEW " "))
(if (= (setq QTY (getstring T "\nEnter QUANTITY: ")) "") (setq QTY " "))
(princ "\nPick Point to Insert the Block.....")
(command "_.insert" (findfile "DXF TAG.dwg") pause 1 1 0)
(setq obj (vlax-ename->vla-object (entlast)))
(foreach att (vlax-invoke Obj 'GetAttributes)
   (if (= (vla-get-Tagstring att) "JOBNAME") (vla-put-textstring att JOBNA))
   (if (= (vla-get-Tagstring att) "JOBNUMBER") (vla-put-textstring att JOBNU))
   (if (= (vla-get-Tagstring att) "PRODUCT") (vla-put-textstring att PDT))
   (if (= (vla-get-Tagstring att) "VIEW") (vla-put-textstring att VIEW))
   (if (= (vla-get-Tagstring att) "QUANTITY") (vla-put-textstring att QTY))
)
(ssadd (entlast) ss)
(setvar 'ATTREQ Areq)
(setvar 'CMDECHO 1)
(sssetfirst nil ss)
(c:burst)
(princ)
)

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 3 of 10

pbejse
Mentor
Mentor

@Anonymous wrote:

 

There might be many more ways to do this but this is the only way that i can think of.  I am open to any ideas if anyone has any input.

 


 

 

I would think so too.

 

Why use attribute blocks If you are planning to explode [ burst ] it afterwards. Use a regular block then change the values per value match.

 

Using the attached none-attribute block [ DXF TAG NA.dwg ]

 

(defun c:INB (/ bn values ip el value)
  (if (and
	(or (tblsearch "BLOCK" (setq bn "DXF TAG NA"))
	    (setq bn (findfile "DXF TAG NA.dwg"))
	)
	(setq values
	       (mapcar '(lambda	(itm)
			  (setq tmp (getstring T (strcat "\nEnter " itm ": ")))
			  (cons itm tmp)
			)

		       '("JOBNAME" "JOBNUMBER" "PRODUCT" "VIEW" "QUANTITY")
	       )
	)
	(setq ip (getpoint "\nPick Point to Insert the Block....."))
      )
    (progn
      (command "_.insert" bn ip 1 1 0)
      (setq el (entlast))
      (command "_.explode" el)
      (while (setq el (entnext el))
	(if (and
	      (eq "TEXT" (cdr (assoc 0 (setq ent (entget el)))))
	      (setq value (assoc (cdr (assoc 1 ent)) values))
	    )
	  (entmod (subst (cons 1 (cdr value)) (assoc 1 ent) ent))
	)
      )
    )
  )
  (princ)
)

If you still want to use your attribute block

 

(defun c:IBB (/ bn values ip blk value)
  (if (and
	(or (tblsearch "BLOCK" (setq bn "DXF TAG"))
	    (setq bn (findfile "DXF TAG.dwg"))
	)
	(setq values
	       (mapcar '(lambda	(itm)
			  (setq tmp (getstring T (strcat "\nEnter " itm ": ")))
			  (cons itm tmp)
			)

		       '("JOBNAME" "JOBNUMBER" "PRODUCT" "VIEW" "QUANTITY")
	       )
	)
	(setq ip (getpoint "\nPick Point to Insert the Block....."))
	(setq blk (vlax-invoke
	      (vlax-get	(vla-get-ActiveLayout
			  (vla-get-ActiveDocument (vlax-get-acad-object))
			)
			'Block
	      )  'InsertBlock ip bn 1 1 1 0))
      )
    (progn
      (foreach itm (vlax-invoke blk 'GetAttributes)
	(if
	      (setq value (assoc (vla-get-tagstring itm) values))
	  	(vla-put-textstring itm (cdr value))
	    )
	)
      (sssetfirst nil (ssadd (entlast)))
      (c:burst)
    )
  )
  (princ)
)

HTH

 

 

 

 

 

 

 

 

 

 

 

0 Likes
Message 4 of 10

Anonymous
Not applicable

See and that work perfect and does exactly what I need. Since I am very new to writing lisp I sometimes dont see the easier option right in front of me. Thanks you for the help. This is just a small step to a much larger picture I am working towards. Hopefully in the future I am going to be able to set up a program that will be able to completely lay out a manufacturing drawings for you then take your parts and export them to another dwg and complete a dxf all automated. I have the dxf stage completely finished now with minimal user input. I am thinking I am going the have to use the newview tool and associate them with the sheet# but I haven't quite got that for to start working out the details 

 

Thanks for all the help

Also thank you @dbhunia for that code as well. 

0 Likes
Message 5 of 10

Anonymous
Not applicable

As I am testing this out, everything works great of course. If I was going to want to insert that block into any DWG how would this code change and what approach should you take. would it be inserting it from a file path? 

0 Likes
Message 6 of 10

dbhunia
Advisor
Advisor

@Anonymous Its my mistake I thought "DXF TAG" is a Wblock ........accordingly I made the code.....

 


@Anonymous wrote:

As I am testing this out, everything works great of course. If I was going to want to insert that block into any DWG how would this code change and what approach should you take. would it be inserting it from a file path? 


As you asked the above highlighted point...... You simply save the block only as a drawing Named as "DXF TAG.DWG" (As per my code.....) and try the code......code will find the "DXF TAG.DWG" file itself....


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 7 of 10

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... If I was going to want to insert that block into any DWG ....


... I would definitely not  do it as in the original description, with one that has values in the Attributes already, needing to be changed, if you're then asking the User for values to change them to.  I would Insert one in "raw" [un-filled-out] form, and let it do the asking for the values, which INSERT is built to do with Attributed Blocks [provided the Attributes are not defined with constant values].  Then BURST it.  Or am I missing something?

 

[The Block can be a drawing file in any location in OPTIONS's Support File Search Path list, and INSERT will find it -- no need for the routine to spell out a file path.  And once it's already in a drawing, you can use it there again without  its needing to reach out to the external file as it would if the file path is built into the routine.]

Kent Cooper, AIA
0 Likes
Message 8 of 10

Anonymous
Not applicable

No, you are not missing anything. 

Using the attributes was just the easiest way I could think to get what I wanted. I was only bursting it so i could keep the text. Whichever way I get the following below into the drawing doesn't matter as long as its in there.

Job Name: "user entry"

Job Number: "user entry"

Product: "user entry"

View: "user entry"

Quantity: "user entry"

0 Likes
Message 9 of 10

Anonymous
Not applicable

I cant get the block to insert in any drawing but but its own... any reason that would be happening?  I tried playing around with it to get it to work and didn't have any luck.

0 Likes
Message 10 of 10

pbejse
Mentor
Mentor

@Anonymous wrote:

I cant get the block to insert in any drawing but but its own... any reason that would be happening?  I tried playing around with it to get it to work and didn't have any luck.


 

I do agree with Kent1Cooper, If the routine will ask the user for the values might as well do it with the native insert command (with ATTREQ set to 1) where you get that pretty dialog box for input. or even better use tool palettes.

 

Whats the point of "bursting" the blocks anyway? keeping the attributes is much better specially if you need to gather info on your drawings [ Quantity per Job number etc.. ].

 

Now getting back to your query, Not sure what you mean sbrathovd. Did you try the suggestion below?

 

 

@Kent1Cooper wrote: 

[The Block can be a drawing file in any location in OPTIONS's Support File Search Path list, and INSERT will find it -- no need for the routine to spell out a file path.  And once it's already in a drawing, you can use it there again without  its needing to reach out to the external file as it would if the file path is built into the routine.]

 

Otherwise, post a sample drawing.

 

 

 

 

 

 

 

 

0 Likes