PDA

View Full Version : Room Attribute Routine



doushkajs353099
2013-04-23, 05:21 PM
Hi All, I have absolutely no idea how to do this but am hoping someone out there can help. I am using AutoCAD LT 2012 and use it to edit and create dwg files recording buildings and their condition (BIM ?). I have room attributes placed on the drawing which display room details from the dwg. What I was hoping for was to access other information based on the room number and show it in the drawing. So if I had say asbestos items recorded in a csv file then I could run a routine with options shown in the command line which would place a symbol in a room where the asbestos was located. Also perhaps render a colour in a room as well to highlight areas. This request hopefully will open discussion on how to tackle the problem as I say I don't know about programming CAD. Thanks in anticipation. Have a great day.

dgorsman
2013-04-23, 07:16 PM
LT has no custmization abilities beyond simple macros, tool palettes, and the Action Recorder.

doushkajs353099
2013-04-24, 07:28 AM
LT has no custmization abilities beyond simple macros, tool palettes, and the Action Recorder.



OK dgorsman, what about this in Revit or full AutoCAD then as i also have access to these apps.

dgorsman
2013-04-25, 03:34 PM
Should be possible in AutoCAD through any number of means. In rough order of complexity: LISP, dotNET, or ARX. As for Revit, I don't know, its not a platform I use. Should be possible, and may even be possible without customization.

fixo
2013-04-25, 04:20 PM
Hi All, I have absolutely no idea how to do this but am hoping someone out there can help. I am using AutoCAD LT 2012 and use it to edit and create dwg files recording buildings and their condition (BIM ?). I have room attributes placed on the drawing which display room details from the dwg. What I was hoping for was to access other information based on the room number and show it in the drawing. So if I had say asbestos items recorded in a csv file then I could run a routine with options shown in the command line which would place a symbol in a room where the asbestos was located. Also perhaps render a colour in a room as well to highlight areas. This request hopefully will open discussion on how to tackle the problem as I say I don't know about programming CAD. Thanks in anticipation. Have a great day.
If you can rich at full AutoCAD version, it's easy to do what you need,
say read csv into complex list, then select in the drawing room numbers
or whathever you have, then retrieve from given list the record matched with this room
number and place all info back from this record in the room block attributes or mtext, etc
Upload here a small drawing with 1-3 rooms and .csv file too I will try to write this code
I'm using A2010 btw

doushkajs353099
2013-04-25, 07:00 PM
If you can rich at full AutoCAD version, it's easy to do what you need,
say read csv into complex list, then select in the drawing room numbers
or whathever you have, then retrieve from given list the record matched with this room
number and place all info back from this record in the room block attributes or mtext, etc
Upload here a small drawing with 1-3 rooms and .csv file too I will try to write this code
I'm using A2010 btw

Hi fixo, thanks for your reply and offer of help, greatly appreciated. Firstly I have been having some problems with saving the XL sheet as a CSV file so I have attached the XL workbook if this helps. I have aslo attached the dwg file saved back as A2010 hope this opens ok. Any assumptions you apply will be fine. Looking forward to working with you on this. Please let me know if you require anything else. Thanks again.

fixo
2013-04-25, 07:33 PM
Okay, I've dowloaded your files on my disk,
will be back tomorrow only,
Cheers :)

fixo
2013-04-25, 07:50 PM
I would place a symbol in a room where the asbestos was located. Also perhaps render a colour in a room as well to highlight areas.
Explain this moment a little more, what you want to retrieve from xls or csv
and where to pass this, below the block ? Show me please a small picture,
just a piece of screenshot as PNG or JPEG

doushkajs353099
2013-04-26, 07:18 PM
Explain this moment a little more, what you want to retrieve from xls or csv
and where to pass this, below the block ? Show me please a small picture,
just a piece of screenshot as PNG or JPEG

Hi fixo, thanks for your reply. Apologies for not responding quicker.
I have been thinking about the procedure a bit more and make the following comments/opinions but will be guided by your superior knowledge of coding etc.

Point One:
After initially placing the room attribute block a user will need to make a decision as to whether asbestos is present or not and thus whether to place an asbestos attribute block. If asbestos is not present then they would proceed to place the next room attribute block. But, if asbestos is present then they would need to call a command to bring in the asbestos attribute block to populate. Data to enter in to the asbestos block could be entered via the command line or via screen pop up block. Not sure how this would be done.
Point Two:
After the asbestos attribute block has been populated it should become invisible and an asbestos symbol inserted above the room attribute. If there are multiple occurances of asbestos in a room then the asbestos symbol could be simply copied and pasted to a specific point in the room plan.
Point Three:
This could be a sticking point. There needs to be a way to click on the room number in the room block and bring up the asbestos block for viewing/editing. Maybe clicking on the asbestos symbol might be better i'm not sure.
Point Four:
It should be the room number in the room block that is the key field in the XL sheet or CSV. So clicking on any room number in the room block would typically query the XL sheet and return the records. The problem here might be that if there are a number of asbestos records in the XL sheet for the same room (due to different materials) then how would they best be displayed.
Lastly:
The asbestos information should of course be on it's own layer.

I hope my explanation is clear enough but let me know. Screen shot attached.

Many thanks, hope your weekend goes well. JS

fixo
2013-04-26, 08:26 PM
Hi JS, I just finished sample code to hatching rooms if these have asbestos
Try it as is on your drawing you've sent me before, other parts of code
I will be finish tomorrow,
btw there is no asbestos block in there, where I can find it on my AutoCAD,
perhaps in Architectural palette?
tell me please


;;-------------------------------------------------- code start ----------------------------------------;;
(defun C:RML (/ *error* asbindexed asbmatches asbtype blkobj dxf ents getattvalue file floorindexed floornum fname found i info
listbounds objs p1 p2 pline plineobj pos plinepoints ptlist read-csv records rmset roominfo rooms room_ref sp sset tmpset x)

(defun *error* (msg)
(if
(vl-position
msg
'("console break"
"Function cancelled"
"quit / exit abort"
)
)
(princ "Error!")
(princ msg)
)
(if (= (logand (getvar "UNDOCTL") 4) 4)
(command "_UNDO" "_END")
)
(princ)
)
;; local functions:

;; return element from association list entry
(defun dxf (key alist) (cdr (assoc key alist)))

;; get lwpolyline vertices
(defun plinepoints (en)
(vl-remove-if
'not
(mapcar '(lambda (x)
(if (= 10 (car x))
(cdr x)
)
)
(entget en)
)
)
)
;; read csv file to a list

(defun read-csv (fname del / strtolst ptlist)

;; by gile
(defun strtolst (str del)
(if (setq pos (vl-string-search del str))
(cons (substr str 1 pos)
(strtolst (substr str (+ pos 1 (strlen del))) del)) (list str)
)
)


(if (setq file (open fname "r"))
(progn
(setq records nil)
(while (setq sp (read-line file))
(setq records (cons (strtolst sp del)records))
)
(close file)
)

)
(if records (reverse records) nil)
)

;; retrieve single attribute value by tag
(defun getattvalue (blkobj atag / at atts attvalue)
(setq atts (vlax-safearray->list
(variant-value
(vla-getattributes blkobj)
)
)
)

(foreach at atts
(if (eq atag (vla-get-tagstring at))
(setq attvalue (vla-get-textstring at)))
)
attvalue
)


;; main part:
;(setq fname (getfiled "Select CSV:" "" "CSV" 4))

(setq records (read-csv fname (chr 59)));<--- \tab = (chr 9) ; = (chr 59) , = (chr 44)

(setq floornum (getstring (strcat "\nSpecify floor number <0>: ")))
(if (eq "" floornum)(setq floornum "0"))
;; remove headers
(setq records (vl-remove (car records) records))

(setq floorindexed (mapcar '(lambda (x)(list (nth 2 x)(nth 4 x)(nth 12 x)))records))
;; extract records that matches to floor number
(setq asbindexed (mapcar 'cdr (vl-remove-if-not '(lambda(x)(eq floornum (car x))) floorindexed)))
(setq asbmatches (mapcar '(lambda(x)(apply 'cons x)) asbindexed))
(setvar "cmdecho" 0)
(setvar "hpname" "SOLID")
(if (= (logand (getvar "UNDOCTL") 4) 4)
(command "_UNDO" "_GROUP")
)
(setq p1 (getpoint "\nSpecify first corner point of floor plan: ")
p2 (getcorner p1"\nSpecify opposite corner: "))
(command "_.SELECT" "_W" p1 p2 "")
(command "_zoom" "_w" p1 p2)
(setq sset (ssget "_P" '((0 . "insert")(2 . "ROOM")(8 . "ROOMTEXT")(66 . 1))))
(setq info (ssnamex sset)
ents (vl-remove-if 'listp (mapcar 'cadr info))
objs (mapcar 'vlax-ename->vla-object ents))
;; select specific room bounds on layer "NC_Attributes"
(setq rmset (ssget "_X" (list (cons 0 "lwpolyline")(cons 8 "NC_Attributes"))))
(setq roominfo (ssnamex rmset)
rooms (vl-remove-if 'listp (mapcar 'cadr roominfo)))
;; get all rooms boundary and associated points of them all
(setq listBounds (mapcar '(lambda (x)(cons x (plinepoints x))) rooms))
;; set counter
(setq i 0)
(while (setq ptlist (cdr (nth i listBounds)))
(if (setq tmpset (ssget "_wp" ptlist '((0 . "insert")(2 . "ROOM")(8 . "ROOMTEXT")(66 . 1))))
(progn
(setq found (ssname tmpset 0))
(setq blkobj(vlax-ename->vla-object found))
(setq room_ref (getattvalue blkobj "ROOM_REF"))
(setq asbtype (cdr (assoc room_ref asbmatches)))
(setq pline (car (nth i listBounds))
plineobj(vlax-ename->vla-object pline))
(command "-bhatch" "_S" pline "" "")
(command "_chprop" "_L" "" "_Color" asbtype "")))
(setq i (1+ i))
)
(*error* nil)
(princ)
)
(prompt "\n\t\t --- Start command with RML ---\n")
(prin1)
(vl-load-com)
(princ)

;;-------------------------------------------------- code end -------------------------------------------;;

doushkajs353099
2013-04-27, 05:29 PM
Hi JS, I just finished sample code to hatching rooms if these have asbestos
Try it as is on your drawing you've sent me before, other parts of code
I will be finish tomorrow,
btw there is no asbestos block in there, where I can find it on my AutoCAD,
perhaps in Architectural palette?
tell me please




;;-------------------------------------------------- code start ----------------------------------------;;
(defun C:RML (/ *error* asbindexed asbmatches asbtype blkobj dxf ents getattvalue file floorindexed floornum fname found i info
listbounds objs p1 p2 pline plineobj pos plinepoints ptlist read-csv records rmset roominfo rooms room_ref sp sset tmpset x)

(defun *error* (msg)
(if
(vl-position
msg
'("console break"
"Function cancelled"
"quit / exit abort"
)
)
(princ "Error!")
(princ msg)
)
(if (= (logand (getvar "UNDOCTL") 4) 4)
(command "_UNDO" "_END")
)
(princ)
)
;; local functions:

;; return element from association list entry
(defun dxf (key alist) (cdr (assoc key alist)))

;; get lwpolyline vertices
(defun plinepoints (en)
(vl-remove-if
'not
(mapcar '(lambda (x)
(if (= 10 (car x))
(cdr x)
)
)
(entget en)
)
)
)
;; read csv file to a list

(defun read-csv (fname del / strtolst ptlist)

;; by gile
(defun strtolst (str del)
(if (setq pos (vl-string-search del str))
(cons (substr str 1 pos)
(strtolst (substr str (+ pos 1 (strlen del))) del)) (list str)
)
)


(if (setq file (open fname "r"))
(progn
(setq records nil)
(while (setq sp (read-line file))
(setq records (cons (strtolst sp del)records))
)
(close file)
)

)
(if records (reverse records) nil)
)

;; retrieve single attribute value by tag
(defun getattvalue (blkobj atag / at atts attvalue)
(setq atts (vlax-safearray->list
(variant-value
(vla-getattributes blkobj)
)
)
)

(foreach at atts
(if (eq atag (vla-get-tagstring at))
(setq attvalue (vla-get-textstring at)))
)
attvalue
)


;; main part:
;(setq fname (getfiled "Select CSV:" "" "CSV" 4))

(setq records (read-csv fname (chr 59)));<--- \tab = (chr 9) ; = (chr 59) , = (chr 44)

(setq floornum (getstring (strcat "\nSpecify floor number <0>: ")))
(if (eq "" floornum)(setq floornum "0"))
;; remove headers
(setq records (vl-remove (car records) records))

(setq floorindexed (mapcar '(lambda (x)(list (nth 2 x)(nth 4 x)(nth 12 x)))records))
;; extract records that matches to floor number
(setq asbindexed (mapcar 'cdr (vl-remove-if-not '(lambda(x)(eq floornum (car x))) floorindexed)))
(setq asbmatches (mapcar '(lambda(x)(apply 'cons x)) asbindexed))
(setvar "cmdecho" 0)
(setvar "hpname" "SOLID")
(if (= (logand (getvar "UNDOCTL") 4) 4)
(command "_UNDO" "_GROUP")
)
(setq p1 (getpoint "\nSpecify first corner point of floor plan: ")
p2 (getcorner p1"\nSpecify opposite corner: "))
(command "_.SELECT" "_W" p1 p2 "")
(command "_zoom" "_w" p1 p2)
(setq sset (ssget "_P" '((0 . "insert")(2 . "ROOM")(8 . "ROOMTEXT")(66 . 1))))
(setq info (ssnamex sset)
ents (vl-remove-if 'listp (mapcar 'cadr info))
objs (mapcar 'vlax-ename->vla-object ents))
;; select specific room bounds on layer "NC_Attributes"
(setq rmset (ssget "_X" (list (cons 0 "lwpolyline")(cons 8 "NC_Attributes"))))
(setq roominfo (ssnamex rmset)
rooms (vl-remove-if 'listp (mapcar 'cadr roominfo)))
;; get all rooms boundary and associated points of them all
(setq listBounds (mapcar '(lambda (x)(cons x (plinepoints x))) rooms))
;; set counter
(setq i 0)
(while (setq ptlist (cdr (nth i listBounds)))
(if (setq tmpset (ssget "_wp" ptlist '((0 . "insert")(2 . "ROOM")(8 . "ROOMTEXT")(66 . 1))))
(progn
(setq found (ssname tmpset 0))
(setq blkobj(vlax-ename->vla-object found))
(setq room_ref (getattvalue blkobj "ROOM_REF"))
(setq asbtype (cdr (assoc room_ref asbmatches)))
(setq pline (car (nth i listBounds))
plineobj(vlax-ename->vla-object pline))
(command "-bhatch" "_S" pline "" "")
(command "_chprop" "_L" "" "_Color" asbtype "")))
(setq i (1+ i))
)
(*error* nil)
(princ)
)
(prompt "\n\t\t --- Start command with RML ---\n")
(prin1)
(vl-load-com)
(princ)

;;-------------------------------------------------- code end -------------------------------------------;;


Hi fixo, I can't believe you have done this so quick, it would have taken me months to get this far, even if I knew how. Very grateful. Now, i'm assuming that this is a script file but does it go somewhere specific in AutoCAD file structure or just drop it in the root location and is there a specific name to give it. Also I am assuming I start it by typing in RML. Please confirm. The asbestos block (AsbestosBlock) is in the attached dwg, not sure why it was not in the first dwg though.

fixo
2013-04-27, 05:46 PM
Hi, JS,
this one was just a quick example,
try extended version instead, let me know how it works
and what to change in there
(used your csv file and first drawing for test)

Later,

91478
Tested on your last drawing, then added some changes
Try attached code instead but change your block name correctly :)
91479

doushkajs353099
2013-04-28, 04:25 PM
Hi, JS,
this one was just a quick example,
try extended version instead, let me know how it works
and what to change in there
(used your csv file and first drawing for test)




91478
Tested on your last drawing, then added some changes
Try attached code instead but change your block name correctly :)
91479


Thanks fixo, I've been trying to get the lisp file to run in ALT 2013 and 2012 but not successful. Can you provide any instructions for me to get it working ok.

Sorry, but maybe i'm missing something obvious here.

JS

fixo
2013-04-28, 05:07 PM
What the thing is ALT, if this one is LT release,
then Lisp will not work except in full AutoCAD ,
you may try to add this expression:
(vl-load-com)
in the command line then press Enter,
then appload lisp
and type: RML to execute
And also did you renamed your block before?
yours is named as AsbestoBlock, rename it on AsbestosBlock
or change block name in code on your existing block name
Let me know after,
Later

In addition see result of program in your second drawing

91482

doushkajs353099
2013-04-29, 06:58 AM
Good morning fixo, i hope you are well. please accept my apologies if there was any confusion over versions of AutoCAD. In my initial question i did mention that i was using AutoCAD LT 2012 as such i thought that the code you had written would work in my version. Anyway, it's ok because i can try / test it in full AutoCAD 2012 now.
I like what i see at the moment and it looks promising. I note your last comments about the AsbestosBlock which was a typo mistake.
I will run through a few times and let you know what happens.

VERY VERY VERY grateful, JS

fixo
2013-04-29, 10:11 AM
Glad you got it to work
Btw, my suggestion is to make attributes invisible if you want,
then just a block image will be shown on screen, that's just an idea of course.
Happy coding :)

doushkajs353099
2013-04-29, 10:26 AM
Hi fixo, i thinke your suggestion is a must to save having too much on the dwg sheet but i will have to come to you for the coding i'm afraid. I'll let you know when i have finished testing out the current version.

Hope you don't mind
Have a great day.

JS

fixo
2013-04-29, 11:26 AM
Okay, to increase the drawing size I could be able to to remove hatches only,
let me know then
Later

doushkajs353099
2013-04-29, 05:23 PM
Hi fixo, i'm just running the lsp file now in full AutoCAD 2012, using ROOMLABELS2 with AsbestosBlock renamed:

RML, starts the code and the first option to enter is the FloorNumber and this is ok however the next option to appear is showing 'Specify the first corner point'. Surely this is for a Rectangle isn't it?.

JS

fixo
2013-04-29, 05:50 PM
Hi JS,
Yes, just select whole floor plan by window points,
(same as you draw rectngle command), first corner, then
opposite corner, replace propmts on whatever you need

doushkajs353099
2013-04-30, 06:32 AM
Morning fixo, after rereading your code it is starting to make sense. However, after starting with RML and entering the FloorNumber i have picked the 'rectangle' as required and now get the 'wait' alert.................after 10mins nothing has happened. This is what i am doing, I have tried drawing the rectangle and enclosing the whole of the floor plan and the room polylines, i have tried drawing the rectangle for each individual room but when i press enter after picking the rectangle the alert 'Wait' pops up - doesn't seem to want to go past this point or am i too impatient.

JS

fixo
2013-04-30, 09:18 AM
You could not put the AsbestosBlock for each individual room
just for whole floor plan only
So you need to select all plan picking 2 window points and wait a few seconds no more,
no other commands is needed
Will be back later,

doushkajs353099
2013-04-30, 11:38 AM
Hi fixo, I have attached a pdf to show you the 'rectangle' i picked on the plan.

JS

fixo
2013-04-30, 02:17 PM
See step-by-step instructions
91501
Red colored are Asbestos blocks,
hatched rooms conains asbest type
returned from CSV file

doushkajs353099
2013-05-04, 04:57 PM
Hi fixo, sorry I have not replied earlier but I have not been well - stomach bug got me!!.

Anyway, I read your step by step instructions but without success as the routine still hangs at the ' Wait ' alert. Not really sure why it should run on your system and not mine. I am running Windows 7 Pro and AutoCAD full 2012. Have you any suggestions?. There are a few other bits of the routine I would like to tidy up but can't at the moment.

Hope your weekend is good for you.

JS

Wanderer
2013-05-06, 08:33 PM
Hi All, I have absolutely no idea how to do this but am hoping someone out there can help. I am using AutoCAD LT 2012 and use it to edit and create dwg files recording buildings and their condition (BIM ?). I have room attributes placed on the drawing which display room details from the dwg. What I was hoping for was to access other information based on the room number and show it in the drawing. So if I had say asbestos items recorded in a csv file then I could run a routine with options shown in the command line which would place a symbol in a room where the asbestos was located. Also perhaps render a colour in a room as well to highlight areas. This request hopefully will open discussion on how to tackle the problem as I say I don't know about programming CAD. Thanks in anticipation. Have a great day.

I'm following this thread with great interest, good stuff so far.

Just curious though if you're working for a client, or if you are a facility? If you work for the facility itself, it's usual for this type of information to be tracked using a CAFM program (discussed in the facilities management forum (http://http://forums.augi.com/forumdisplay.php?519-Facilities-Management-In-Practice) here on AUGI, or in product-specific forums like archibus and fm:systems, etc).
Some folks do use Map3d for data tracking like that as well.
And, Revit probably has more tools than I'm aware of to query and display information. Clyne Curtis did an interesting class on using Revit to create color-coded floor plans based on data associated with rooms. They will be posted here (http://forums.augi.com/forumdisplay.php?1271-Autodesk) (2008-2010 I know he had applicable classes), but, they're not up yet. Keep an eye out.

doushkajs353099
2013-05-07, 08:05 AM
Hi Wanderer, many thanks for your reply / comment. You are quite right about the tracking of this information and in reality this is the way to do it. What i am working with here is not quite a CAFM application it is actually a database (Concerto) which has the ability to interrogate drawings via a third party app (CAD.NET). A poor man's approach and is making things a bit akward. I am responsible for the admin on this database and am looking for ways to make it work better for us.

Any advice or tips ALWAYS welcome, thanks.

Wanderer
2013-05-07, 06:58 PM
Hi Wanderer, many thanks for your reply / comment. You are quite right about the tracking of this information and in reality this is the way to do it. What i am working with here is not quite a CAFM application it is actually a database (Concerto) which has the ability to interrogate drawings via a third party app (CAD.NET). A poor man's approach and is making things a bit akward. I am responsible for the admin on this database and am looking for ways to make it work better for us.

Any advice or tips ALWAYS welcome, thanks.

Ah, I definitely understand. We make due with the tools we are given.