PDA

View Full Version : Room Tag LISP Routine



rmjcorp
30th Sep 2011, 06:52 pm
I would like to know if there exists a LISP Routine that will allow the user to click on data(text and a polyline) in a drawing and have it inserted into a pre made block with attributes? For example, if an architect sends me a DWG with room tags, employees names (seating), and I create a poly line for each room, and I have a block already made with those 3 attributes, can I select the data and have it inserted into the block? I would like to generate excel spread sheets with columns for the RM#, Employee seating, and SF as the end result. Thank you in advance.

Tharwat
30th Sep 2011, 07:09 pm
Would the data (text or polyline) gonna be replaced into the attribute text in a block ?

rmjcorp
30th Sep 2011, 07:13 pm
Yes. basically it would be the text in the existing drawing. I would then insert my block into each room and take the text(from the existing drawing) and copy it into the block as a field. This way the data is linked and if changes are made to the original text, the attributes would reflect this change.

irneb
30th Sep 2011, 07:34 pm
A few questions:


Is the text always inside the polyline it refers to?
Is there various other possible texts which may per chance also be there?
Is there some way to figure out which text is which, e.g. different layers?

If all = Yes then it's possible to write something where you simply have to pick the polyline. Otherwise you'd need to pick each text as well.

I have an old routine, but it's made specifically for our office, so it might need a lot of modification to suit your needs.

rmjcorp
30th Sep 2011, 07:41 pm
1. Yes
2. Yes (but I can hide them during task)
3. Yes
-I can put employee names on own layer
-I can put room number tag on its own layer
-I can make the polylines on there own layer
Another note, I am not opposed to making multiple selections, however if I understand what you are suggesting is to just replace all three by selecting the polyline, which would be amazing.

Tharwat
30th Sep 2011, 07:57 pm
I guess you need a routine to add objects to block . :)

If yes ?

check this out ...

http://lee-mac.com/addobjectstoblock.html

rmjcorp
30th Sep 2011, 08:12 pm
I dont think this will work for me because I am trying to add txt to attributes within a block. This way I can extract later and all 3 attributes will be represented together in the spreadsheet. For example, I could extract data that tells me "John Doe"(employee) is in room 201 that is 150sf.

Tharwat
30th Sep 2011, 08:58 pm
Would this help you with it .. ?
Select the texts which they are three text as you have mentioned and after that select a block which has attributes which are also three to contain texts in atts.

This is if I understood your needs well ... :)


(defun c:TesT (/ acdoc ss blk e n sset str)
;; Tharwat 30. Sep. 2011 ;;
(vl-load-com)
(setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(if (and
(setq ss (ssget '((0 . "*TEXT"))))
(setq blk (car (entsel "\n Select Attributes in Block :")))
(eq (cdr (assoc 0 (setq e (entget blk)))) "INSERT")
)
(progn
(setq n -1)
(repeat (setq i (sslength ss))
(setq sset (ssname ss (setq i (1- i))))
(setq str (cons (cdr (assoc 1 (entget sset))) str))
)
(setq str (reverse str))
(vlax-for x (vla-item (vla-get-blocks acdoc) (cdr (assoc 2 e)))
(if (eq (vla-get-objectname x) "AcDbAttributeDefinition")
(vla-put-textstring x (nth (setq n (1+ n)) str))
)
)
(vla-regen acdoc AcAllViewports)
)
(princ)
)
(princ)
)


Tharwat

rmjcorp
30th Sep 2011, 10:29 pm
It does not insert the selected into the block. I get this error "Select Attributes in Block :; error: ActiveX Server returned an error:
Parameter not optional"

Tharwat
1st Oct 2011, 05:20 am
It does not insert the selected into the block. "

What is that selected ( lines , texts , polylines , ....... etc) ????



I get this error "Select Attributes in Block :; error: ActiveX Server returned an error:
Parameter not optional"

That's odd ,

the required things for the routine :

1- should have attributed block which should have 3 attributes in it .
2- when invoking the routine , you should select texts to be inserted in the attributed block and which is going to be replaced with the attributes (texts).

rmjcorp
1st Oct 2011, 06:03 am
Polyline for the area attribute
text for the room # and employee name attributes

Do the attributes need to be any special designations?

Tharwat
1st Oct 2011, 06:07 am
Do the attributes need to be any special designations?

No , it is normal attributes .

Upload a piece of drawing shows before and after of your needs ( or an image) .

rmjcorp
1st Oct 2011, 06:43 am
Here is the before and after

Tharwat
1st Oct 2011, 06:52 am
Ok , invoke the routine and select ( for example ) text ( Alex and 253 and double-office ) and after that select the attributed block which is as I can see
in your images in office No# 254 .

And insert the same name of the attributed block that you have already selected to be inserted with the new texts .

rmjcorp
1st Oct 2011, 07:07 am
Oh I think I figured it out.
Basically I have to re-insert the block after I run the routine. Am I correct?

Tharwat
1st Oct 2011, 07:08 am
Oh I think I figured it out.
Basically I have to re-insert the block after I run the routine. Am I correct?

Of course .... :)

rmjcorp
1st Oct 2011, 07:20 am
Awesome! Any way to change the order of which names get inserted where? If im pushing my luck just let me know :)

Tharwat
1st Oct 2011, 07:25 am
Awesome! Any way to change the order of which names get inserted where? If im pushing my luck just let me know :)

I really knew that you'd ask this question . :)

So of course yes there is a way , but you have to select each text a lone ( one by one ) . What you think ?


Tharwat

rmjcorp
1st Oct 2011, 07:28 am
I would rather do one by one because I will have to run an area routine for the area attribute anyways. I really wish I could just learn how to write this stuff for myself. Any suggestions on where to start on my own?

Tharwat
1st Oct 2011, 07:55 am
Try this with singular selection for each text to become in order ...



(defun c:TesT (/ acdoc ss blk e n sset str)
;; Tharwat 30. Sep. 2011 ;;
(vl-load-com)
(setq n -1
acdoc (vla-get-ActiveDocument (vlax-get-acad-object))
)
(while
(setq ss (ssget "_+.:S" '((0 . "*TEXT"))))
(setq sset (ssname ss 0))
(setq str (cons (cdr (assoc 1 (entget sset))) str))
)
(if
(and str
(setq blk (car (entsel "\n Select Attributed Block :")))
(eq (cdr (assoc 0 (setq e (entget blk)))) "INSERT")
)
(progn
(vlax-for x (vla-item (vla-get-blocks acdoc) (cdr (assoc 2 e)))
(if (eq (vla-get-objectname x) "AcDbAttributeDefinition")
(vla-put-textstring x (nth (setq n (1+ n)) str))
)
)
(vla-regen acdoc AcAllViewports)
)
(princ)
)
(princ)
)


Tharwat

rmjcorp
1st Oct 2011, 08:09 am
Have you ever used the A2A.lsp? it puts an area into an attribute within a block. I am not sure if I am allowed to post it on the board but that is what I am looking for with the insertion method.

Tharwat
1st Oct 2011, 08:11 am
Have you ever used the last routine that I have posted and modified for you first ?

rmjcorp
1st Oct 2011, 08:21 am
yes I tried it but it would not insert correctly. it also does not allow me to pick the text like it did with the first one.

Tharwat
1st Oct 2011, 08:53 am
What's that thing which is not being inserted correctly ??

You should read about functions first to know the differences between both of them ..

ssget (would allow you to use window selection to select many entities )

http://docs.autodesk.com/ACDMAC/2012/ENU/filesALRMac/GUID-9DA52C39-0A0D-48B4-82DA-D011D9EDC0E-212.htm

entsel ( would allow you to select only one entity )

http://docs.autodesk.com/ACDMAC/2012/ENU/filesALRMac/GUID-66C43B0D-85D3-49FF-8653-48ADA33817E-83.htm

rmjcorp
1st Oct 2011, 09:02 am
ok i will check it out. I actually was able to modify the A2A.lsp to be able to grab texts as well as polylines and it inserts it in to the block without having to re-insert the block. I still have to use 2 routines(1 for text attributes and 1 for the area attribute), but this way it allows me to pick a text and select the exact attribute I want it to replace(this way it goes where I want it to). If you would like to see it I will post it but like I said before I am not familiar with what can be posted on public boards or not. It was a LISP originally made by Lee Mac.

Lee Mac
1st Oct 2011, 01:16 pm
1- should have attributed block which should have 3 attributes in it .
2- when invoking the routine , you should select texts to be inserted in the attributed block and which is going to be replaced with the attributes (texts).

Tharwat,

You are modifying the Attribute Definition objects (ATTDEFs) in the Block Definition (BLOCK), not the Attribute Reference objects (ATTRIBs) in the Block Reference (INSERT).

This is setting the Attribute Default Text for the Block Definition, not the Attribute Values for the single selected Block Reference.

We discussed this only the other day in this (http://www.cadtutor.net/forum/showthread.php?62888-copy-multiline-attribute-data-to-command-line/page2) recent thread. :facepalm:

rmjcorp
1st Oct 2011, 04:28 pm
Lee Mac,

Is there a way to add the to A2A.lsp, the ability to insert room number, employee name, and area? I dont mind if I had to run the routine multiple time by pressing space bar, however if I need to type alternate routines it can get annoying.

Tharwat
1st Oct 2011, 05:17 pm
Tharwat,

You are modifying the Attribute Definition objects (ATTDEFs) in the Block Definition (BLOCK), not the Attribute Reference objects (ATTRIBs) in the Block Reference (INSERT).

This is setting the Attribute Default Text for the Block Definition, not the Attribute Values for the single selected Block Reference.

We discussed this only the other day in this (http://www.cadtutor.net/forum/showthread.php?62888-copy-multiline-attribute-data-to-command-line/page2) recent thread. :facepalm:

Hi Lee .

That discussion was not completed to end and my post No# 17 in that thread shows clearly my direct ask to it, and when it is supported with your marvelous examples I did lost in them since they are much and and my question was to know the differences . :)

Regards,

Tharwat

Lee Mac
1st Oct 2011, 05:20 pm
Is there a way to add the to A2A.lsp, the ability to insert room number, employee name, and area? I dont mind if I had to run the routine multiple time by pressing space bar, however if I need to type alternate routines it can get annoying.

Yes, I could probably make those modifications - but not on voluntary time.

Lee

Lee Mac
1st Oct 2011, 05:21 pm
That discussion was not completed to end and my post No# 17 in that thread shows clearly my direct ask to it

You wish to know the differences between an ATTDEF entity and an ATTRIB entity?

Tharwat
1st Oct 2011, 05:28 pm
You wish to know the differences between an ATTDEF entity and an ATTRIB entity?

Correct , According to your notifications to me about the attributes in general , I'd like to get it right and to know my repeated mistake with it .

Thanks

Lee Mac
1st Oct 2011, 06:05 pm
The ATTDEF entity is the Attribute Definition and resides in the Block Definition (BLOCK in the Block Table). The Attribute Definition contains the Tag String, Prompt String and Default value of the Attribute. It is the entity that is created when you use the ATTDEF command.

The ATTRIB entity is the Attribute Reference and resides in the Block Reference (INSERT). This entity has only a Tag String and Attribute Value (or Text String).

There may be many Block References (INSERTs) inserted in the drawing, but only one Block Definition for each block name. Similarly, there are ATTRIB entities in each Attributed block inserted in the drawing, but each of these reference a single ATTDEF entity in the Block Definition.

Think about it as the Block Definition (BLOCK) being the 'blue-prints' and the Block Reference (INSERT) being the 'construction', hence there is only one set of blue-prints but maybe many constructions created from the blue-prints.

To help illustrate the structure of an Attribute Block Definition and Attributed Block Reference, I have created an example program (attached). The program will create a simple block definition with a single attribute definition, then insert a reference of this definition at the Origin. The program will then list the DXF data of the inserted Block Reference, so that you may see the ATTRIB entity structure.

After studying the attached program, have a careful read of this (http://www.cadtutor.net/forum/showthread.php?48577-Getting-a-value-for-a-specific-attribute&p=330778#post330778) post.

If you still have questions, ask.

Lee

Tharwat
2nd Oct 2011, 12:02 pm
Thanks for the great efforts Lee , highly appreciated .

Now I realized the differences between the Attribute entity and attribute Definition when you have just mentioned in your esteemed last reply which is


The ATTDEF entity is the Attribute Definition and resides in the Block Definition (BLOCK in the Block Table). The Attribute Definition contains the Tag String, Prompt String and Default value of the Attribute. It is the entity that is created when you use the ATTDEF command.

The ATTRIB entity is the Attribute Reference and resides in the Block Reference (INSERT). This entity has only a Tag String and Attribute Value (or Text String).


Honestly I have been thinking that the attribute definition is the same as the one resides in a Block , which is of course completely different as you have explained .

Thanks a lot .

Tharwat

Lee Mac
2nd Oct 2011, 02:28 pm
Glad to have removed the confusion and that my explanation was comprehensible. :beer:

rmjcorp
10th Oct 2011, 06:25 am
Is there a possibility to create a routine that will allow me auto populate a specific room tag block with every element within a specified polyline.
here is what I would ideally want to have happen..

1. create a polyline around a room(as a boundary)
2. create text or mtext for items such as employee, employee ID #, Department, and Building
3. insert a block with fields for area, employee, employee ID #, department, and building
4. run LISP to auto populate fields in block
5. run extraction to pull data into tables or excel spreadsheets.

I have hundreds of rooms to perform this type of data management on and I would like to streamline the system a lot. I would be willing to pay someone to create this lisp if need be.