Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 28

Thread: Room Attribute Routine

  1. #11
    Member
    Join Date
    2013-01
    Posts
    28
    Login to Give a bone
    0

    Thumbs up Re: Room Attribute Routine

    Quote Originally Posted by fixo View Post
    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:
    ;;--------------------------------------------------  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.
    Attached Files Attached Files

  2. #12
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: Room Attribute Routine

    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,

    ROOM_LABELS.lsp
    Tested on your last drawing, then added some changes
    Try attached code instead but change your block name correctly
    ROOM_LABELS2.LSP
    Last edited by fixo; 2013-04-27 at 06:33 PM.
    "The whole problem with the world is that fools and fanatics are always
    so certain of themselves, and wiser people so full of doubts."
    Bertrand Russell

  3. #13
    Member
    Join Date
    2013-01
    Posts
    28
    Login to Give a bone
    0

    Unhappy Re: Room Attribute Routine

    Quote Originally Posted by fixo View Post
    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)




    ROOM_LABELS.lsp
    Tested on your last drawing, then added some changes
    Try attached code instead but change your block name correctly
    ROOM_LABELS2.LSP

    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

  4. #14
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: Room Attribute Routine

    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

    ROOM-LABELS.png
    Last edited by fixo; 2013-04-28 at 05:31 PM.
    "The whole problem with the world is that fools and fanatics are always
    so certain of themselves, and wiser people so full of doubts."
    Bertrand Russell

  5. #15
    Member
    Join Date
    2013-01
    Posts
    28
    Login to Give a bone
    0

    Default Re: Room Attribute Routine

    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

  6. #16
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: Room Attribute Routine

    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
    Last edited by fixo; 2013-04-29 at 10:12 AM. Reason: spell check
    "The whole problem with the world is that fools and fanatics are always
    so certain of themselves, and wiser people so full of doubts."
    Bertrand Russell

  7. #17
    Member
    Join Date
    2013-01
    Posts
    28
    Login to Give a bone
    0

    Default Re: Room Attribute Routine

    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

  8. #18
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: Room Attribute Routine

    Okay, to increase the drawing size I could be able to to remove hatches only,
    let me know then
    Later
    "The whole problem with the world is that fools and fanatics are always
    so certain of themselves, and wiser people so full of doubts."
    Bertrand Russell

  9. #19
    Member
    Join Date
    2013-01
    Posts
    28
    Login to Give a bone
    0

    Default Re: Room Attribute Routine

    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

  10. #20
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: Room Attribute Routine

    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
    "The whole problem with the world is that fools and fanatics are always
    so certain of themselves, and wiser people so full of doubts."
    Bertrand Russell

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Attribute Definition Copying Routine
    By chris.harmon682006 in forum AutoLISP
    Replies: 11
    Last Post: 2015-02-25, 08:19 PM
  2. Room Attribute Routine
    By doushkajs353099 in forum AutoLISP
    Replies: 27
    Last Post: 2013-05-07, 06:58 PM
  3. Attribute extraction routine
    By draftsit in forum AutoLISP
    Replies: 1
    Last Post: 2009-03-04, 07:32 PM
  4. Replies: 2
    Last Post: 2007-05-11, 11:25 AM
  5. Attribute Extraction routine
    By isosa in forum AutoLISP
    Replies: 14
    Last Post: 2006-03-10, 04:37 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •