Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting Geometric data to an Atrribute

Status
Not open for further replies.

Rzbker

Technical User
Jun 17, 2003
7
US
I am trying to define a simple block with attributes. I want to have a field that has the insertion coordinates of the inserted block automatically written to an attribute value.
Is there some way that I can put a string command in the value definition line of attdef that will get this info while the block is in the insertion process.


Thanks in advance

Go Hogs Go!
 
Are you doing this interactively? (i.e. Is the user picking a spot and you want to fill in the location for him?). Or, are you looking to do it all with code (i.e. Insert Correct Block, Set Insertion Point, Fill out Attributes)
 
The user will be picking the spot. We are doing a drainage structure inventory from asbuilt plans and are locating inlet structures on aerial photographs. We are having the user insert the block and fill out data fields (i.e. type, size, invert, etc.) We are then importing them into ArcMap to created a geodata base for the city. We have found that the more information and graphic editing that we can do in AutoCad, the better.
Thanks for you help in advance
 
I pieced this together from some old code, give it a try.

(defun C:FILL_ATT_PTS ()
(vl-load-com)
(setq PT1 (getpoint "\nSelect Insertion Point")
BLK_NAME "YOUR_BLK_NAME_HERE" ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
SCLFAC 1.0
)
(command "_.INSERT" BLK_NAME PT1 SCLFAC "" "")
(setq BALENT (cdr (assoc -1 (entget (entlast)))))
(setq ATTLIST
(vlax-safearray->list
(variant-value
(vla-getattributes (vlax-ename->vla-object BALENT))
)
)
)
(setq TAGNAME "YOUR_TAG_NAME_HERE" ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
PTLIST (strcat (rtos(car PT1)2 4) "," (rtos(cadr PT1)2 4)) ;PTS to X,Y
) ;setq
(foreach ITEM ATTLIST
(if (= (vla-get-tagstring ITEM) TAGNAME)
(vla-put-textstring ITEM PTLIST)
) ;if
) ;foreach
(princ)
) ;defun
 
Thanks Borunit,

Do I run this as a lisp or what?
 
Oh,
Yes, first save the portion I wrote (beginning with "(defun" ) as FILL_ATT_PTS.lsp on your local hard drive (highlight and copy that portion to Notepad and then SAVEAS FILL_ATT_PTS.lsp). In AutoCAD, go to TOOLS >> LOAD APPLICATION and then browse for it on your computer, and load it. Type in FILL_ATT_PTS on the command line. I am not sure how much you know about LISP but you have to edit the program to fit your case. The lines that have the exclamation marks !!!! need your specific information (Block Name and Tag Name in the block). Let me know if I am too confusing.
 
No sir, you are not confusing. I do have some knowledge of lisp routincs (Lost In Stupid Parenthesis, I believe). I will give it a go and again, I sure do appreciate your help.
 
Borgunit,

I used this code:


(defun C:inlet ()
(vl-load-com)
(setq PT1 (getpoint "\nSelect Insertion Point")
BLK_NAME "test";
SCLFAC 1.0
)
(command "_.INSERT" BLK_NAME PT1 SCLFAC "" "")
(setq BALENT (cdr (assoc -1 (entget (entlast)))))
(setq ATTLIST
(vlax-safearray->list
(variant-value
(vla-getattributes (vlax-ename->vla-object BALENT))
)
)
)
(setq TAGNAME "XY";
PTLIST (strcat (rtos(car PT1)2 4) "," (rtos(cadr PT1)2 4)) ;PTS to X,Y
) ;setq
(foreach ITEM ATTLIST
(if (= (vla-get-tagstring ITEM) TAGNAME)
(vla-put-textstring ITEM PTLIST)
) ;if
) ;foreach
(princ)
) ;defun

I renamed the lsp to "inlet". When I tried using a block (named test, a small poygon with a node at center) with no attributes defined, I get a message after insert prompt, "Select Insertion PointActiveX Server returned an error: Invalid index".

I tried redefining the block to where I have an "XY" attribute tag already defined, I get the message, "Select Insertion PointUnterminated Complex Entity
ActiveX Server returned an error: Invalid index".

Hmmmmmm.......What do you think?


 
By the way, the program has no error handling.
I am not able to duplicate the problem. It works ok for me. Let me ask a few things.

-Is the block in the AutoCAD support search path?
-When you retested the routine, did you erase the old block and purge it before retrying?
-How far does it go?
--Does it prompt for insertion point?
--Does it let you pick a point?
--Does the dialog for the attributes appear?

Let me know.
 
Borg,

Found the problem. The attribute has to be set to verify in the block. It works great now.

Thanks a BUNCH, I certainly owe you one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top