room names to attribute

room names to attribute

Anonymous
Not applicable
2,345 Views
20 Replies
Message 1 of 21

room names to attribute

Anonymous
Not applicable

I need a lisp routine that will allow me to pick a room name or location and then pick a block and have it fill in the "location attribute". The blocks would be fire alarm and security device placed on a floor plan. I would then use data extraction to pull the attribute info for filling in excel spreadsheet. Ideally it would have a dialog block for putting in a prefix, I could type in something like "1st floor bldg A" If anyone has anything or can get me sent in the right direction I would be very appreciative for the help. I haven't done autolisp code writing for several years.

Thank You

Rick

0 Likes
2,346 Views
20 Replies
Replies (20)
Message 2 of 21

Sea-Haven
Mentor
Mentor

Post a example dwg with the relevant block.

0 Likes
Message 3 of 21

Anonymous
Not applicable

Here's a sample drawing with a card reader and a camera block which is typical of what we use

Message 4 of 21

Sea-Haven
Mentor
Mentor

I can see a lot of possible problems, but it is possible to find all blocks using a text on a layer.

 

Step 1 is find a text

Step2 is make a bpoly

step 3 is get all text and any blocks

Step 4 is make some form of list as you require

 

So yes its possible, re card reader it was on outside of building so a problem. Needs a different search method, a touch rather than within.

 

A better sample would be good with more blocks. To test code. This should exist already some one will have I just have the method somewhere. Need out put sample like

"Level 2" desription1 description2 Block1name atts……..

"Level 2" desription1 description3 Block1name

"Level 2" desription1 description4 Block1name atts...........

 

 

screenshot213.png

 

 

0 Likes
Message 5 of 21

pbejse
Mentor
Mentor

@Anonymous wrote:

I need a lisp routine that will allow me to pick a room name or location and then pick a block and have it fill in the "location attribute". The blocks would be fire alarm and security device placed on a floor plan.


Not enough information for me to follow,  on your sample dawing file, what is supposed to be the value for LOCATION" on  "CAM-1" block ? is it "LOBBY/AC06"? and a TEXT object at that.

 

Are you saying "FIXED CAMERA" and "CARD READER" block are already in place?  In your case you have to select the name then the block, there is no easy way.

 

A lot of times I suggested before to use a "FLOOR" to identify a room on a non-plotable layer.

 

room.JPG

[ width and color are exagerated for discussion purposes ]

 

Anyt time a program need to identify what's in a room, it uses the floor as the boundary along with the use of filters.

 

Just bringing it out there for you.

 

 

 

0 Likes
Message 6 of 21

Sea-Haven
Mentor
Mentor

Agree lack of information no probs finding stuff inside rooms but need to know what to look for.

0 Likes
Message 7 of 21

Anonymous
Not applicable

I realize I didn't explain myself very good. what I'm looking for is a routine that allows me to pick the room name text and then select a block that located ether by that room or in it. The selected text would be populate the block in a attribute which when I completed I could use data extraction to fill in a spreadsheet that would have a block address and location which is used for a spreadsheet schedule. I have a lisp routine that addresses the block as a attribute already. I had worked for a company that had such a process and I would like to use it at my new company

0 Likes
Message 8 of 21

pbejse
Mentor
Mentor

@Anonymous wrote:

 ...What I'm looking for is a routine that allows me to pick the room name text and then select a block that located ether by that room or in it


Ok then.

(Defun c:labeltoblock (/ blk txt)
  (while
    (and
      (princ "\nRoom label")
      (setq txt (ssget "_+.:S:E:L" '((0 . "TEXT"))))
      (princ "\nSelect CARD READER/FIXED CAMERA")
      (setq blk (ssget "_+.:S:E:L" '((0 . "INSERT") (66 . 1))))
    )
     (setpropertyvalue
       (ssname blk 0)
       "LOCATION"
       (getpropertyvalue (ssname txt 0) "Textstring")
     )
  )
  (princ)
)

We were aiming to eliminate the tedious task of selecting one label per block, that is what all this queries and sugestions are all about.

 

Hope that short routine will work for you

 

0 Likes
Message 9 of 21

pbejse
Mentor
Mentor

In case you need to select tow TEXT objects [ to which there are ]

 

 

(Defun c:labeltoblock (/ _2Becomes1 blk txt)
(Defun _2Becomes1 (lst)
 (substr (apply 'strcat
	(mapcar '(lambda (S)
		   (Strcat " "
		       (getpropertyvalue s "Textstring"))) lst))
  	 2
	 )
  )        
  (while
    (and
      (princ "\nRoom label")
      (setq txt (ssget "_:L" '((0 . "TEXT"))))
      (princ "\nSelect CARD READER/FIXED CAMERA")
      (setq blk (ssget "_+.:S:E:L" '((0 . "INSERT") (66 . 1))))
    )	
    (setpropertyvalue
       (ssname blk 0)
       "LOCATION"
        (_2Becomes1 (vl-remove-if 'listp
		      (mapcar 'cadr(ssnamex txt))))
     )
  )
  (princ)
)

 

 

HTH

Message 10 of 21

Sea-Haven
Mentor
Mentor

You can get all blocks inside the room by just looking for the text room name, that is easy the issue if you want outside also but how do you define the rules for this by distance ? 

 

A room would return stuff like tables, chairs pc and a camera if within.

 

Or has Pbe given you the answer.

0 Likes
Message 11 of 21

john.uhden
Mentor
Mentor

If each room had a closed polyline (invisible or not), then just text on an appropriate layer for each "attribute" would suffice.  I am thinking that with quadrilateral room outlines my original @Anonymous function could handle finding any piece of data about any room.  No need for blocks unless their curvilinear contents are important to the looks of the finished product.

John F. Uhden

0 Likes
Message 12 of 21

Anonymous
Not applicable

I've been using you lisp routine it works wonderfully except it doesn't recognize Mtext I tried to edit it but I keep getting the error message"ADS request error"

Thanks

0 Likes
Message 13 of 21

Sea-Haven
Mentor
Mentor

(getpropertyvalue (car (entsel)) "Textstring") will return an error for Mtext but not Text, you will need to use either a entget or a Vla-get-textstring method, then the ssget can use *text

 

Pbejse Bricscad does not support the get and put property methods at present.

0 Likes
Message 14 of 21

Anonymous
Not applicable
(Defun c:labeltoblock (/ _2Becomes1 blk txt)
(Defun _2Becomes1 (lst)
 (substr (apply 'strcat
	(mapcar '(lambda (S)
		   (Strcat " "
		       (getpropertyvalue s "Textstring"))) lst))
  	 2
	 )
  )        
  (while
    (and
      (princ "\nRoom label")
      (setq txt (ssget "_:L" '((0 . "TEXT"))))
      (princ "\nSelect CARD READER/FIXED CAMERA")
      (setq blk (ssget "_+.:S:E:L" '((0 . "INSERT") (66 . 1))))
    )	
    (setpropertyvalue
       (ssname blk 0)
       "LOCATION"
        (_2Becomes1 (vl-remove-if 'listp
		      (mapcar 'cadr(ssnamex txt))))
     )
  )
  (princ)
)

 

I'm a bit inexperienced in lisp programming so I'm a bit confused as to your post. I included the code any help would be apricated 

0 Likes
Message 15 of 21

Sea-Haven
Mentor
Mentor

2 comments 

 

1 getproperty does not appear to work with Mtext so code needs to use a different method. Probably vla-get-textstring As the code was originally supplied by Pbejse thought he would update. He is a good programmer I expect he will update.

 

2 A lot of code is used in other software like Bricscad, Intellicad, Autocad Mac, Nanocad etc etc some things work other methods dont. Whilst VL code does not work in Autocad Mac getproperty does.

 

0 Likes
Message 16 of 21

Anonymous
Not applicable

I tried replacing the getproertyvalue text with vla-get-textstring and it gives a error "too few arguments". I completely lost! any help

0 Likes
Message 17 of 21

dlanorh
Advisor
Advisor

What CAD package are you using?

 

getpropertyvalue only works on (type = ENAME) but doesn't work in some (most) other equivalent CAD packages eg BricsCAD; whilst vla-get-textstring only works on (type = VLA-OBJECT), so you cannot just substitute one for the other without converting between entities (ENAME) and Objects (VLA-OBJECT).

I am not one of the robots you're looking for

0 Likes
Message 18 of 21

Anonymous
Not applicable

I'm using autocad 2021 

the below program works great on text but not on mtext. Being inexperience I confused as to why

(Defun c:labeltoblock (/ _2Becomes1 blk txt)
(Defun _2Becomes1 (lst)
 (substr (apply 'strcat
	(mapcar '(lambda (S)
		   (Strcat " "
		       (getpropertyvalue s "Textstring"))) lst))
  	 2
	 )
  )        
  (while
    (and
      (princ "\nRoom label")
      (setq txt (ssget "_:L" '((0 . "TEXT"))))
      (princ "\nSelect CARD READER/FIXED CAMERA")
      (setq blk (ssget "_+.:S:E:L" '((0 . "INSERT") (66 . 1))))
    )	
    (setpropertyvalue
       (ssname blk 0)
       "LOCATION"
        (_2Becomes1 (vl-remove-if 'listp
		      (mapcar 'cadr(ssnamex txt))))
     )
  )
  (princ)
)

 

0 Likes
Message 19 of 21

dlanorh
Advisor
Advisor

It only allows the selection of text on unlocked layers in the ssget

 

 

 

(setq txt (ssget "_:L" '((0 . "TEXT"))))

 

 

 

If you want to play with "MTEXT" and "TEXT" change

 

 

 

'((0 . "TEXT"))

TO

'((0 . "*TEXT"))

OR JUST MTEXT

'((0 . "MTEXT"))

 

 

 

The '((0 . "TEXT")) is a filter where the 0 is an integer dxf code denoting an entity type and the "TEXT" the type of entity, so this filter means only select "TEXT" entities. Be aware that extracting the text string of an MTEXT entity using

 

(getpropertyvalue s "Textstring")

will return any MTEXT inline formatting as part of the string

 

I am not one of the robots you're looking for

0 Likes
Message 20 of 21

Sea-Haven
Mentor
Mentor

Dlanorh (getpropertyvalue (car (entsel)) "Textstring") returns an error if pick mtext. Text is ok.

 

Select object: ; error: ADS request error


What are you doing different ?

 

0 Likes