Jump to content
iCADSolutions

LISP for importing data to attribute, by selection of block individually

Recommended Posts

iCADSolutions

My condition:
I use AutoCAD to do Fire Alarm plans for a client.
One of the redundant things I have to do is label a device on a floor plan with the same label as the same device on a riser diagram on a layout sheet.
I construct my riser after laying the devices out on the floor plan.
My problem is I have to do the label twice which takes a ton of time. Once on the floor plan and the same label for that device on the riser diagram.

Possible solution:
1.  Go through Label the block attribute once on floor plans. The labels are sequential once inputted.
2. Extract those attributes
3. Import those attributes into the blocks on the riser diagram...but individually. 

I want to be able to select the block and import the data in a one-to-one ratio in sequence as I go through selecting the corresponding block on the riser diagram.

Basically after I've exported the data I want, I want to import the data on a block by block basis. I want to click a block and import a string a data, the next block i select takes the next string of data in the list sequentially and so on.

 

Does something like that exist? Is that possible? Forever grateful.

 

  • Like 1

Share this post


Link to post
Share on other sites
BIGAL
Posted (edited)

I pick stuff in model like text and its updated in a block 4 layouts away no jumping to layouts or anything so bottom line is yes it can be done. The block or blocks in my case multi lines must exist it uses a key to search say the riser number as you add riser 52 you look for the riser diagram block and find matching attribute 52 I guess if not then add. 

 

The program has various options you can run and changes different attributes within the block x&y, name, in, out etc.

 

Its probably not a freebie. As what I have would need a full rewrite to suit, but happy to discuss.

Edited by BIGAL
  • Like 1

Share this post


Link to post
Share on other sites
Steven P

Would this give you a starting point?

 

  • Like 1

Share this post


Link to post
Share on other sites
iCADSolutions

Thank you both for the feedback. Taking a look into the options available to me.

Share this post


Link to post
Share on other sites
Emmanuel Delay
Posted (edited)

Is that riser diagram  drawn on layout (paper space)?   It would be easier if both are drawn on Model space.

And those blocks are identical, right?  Or at least they have the same attributes with the same tags in the same order, right?

 

 

----

EDIT: anyway, try this.

3 user functions.

 

Either

Command EIO: select source, select destination, source, destination, ... press enter to exit loop.

 

Or 

EMB: select source, source, source, ... press enter to exit loop.

then IMB: select destination, destination, destination, ... press enter to exit loop.

 

Those last two functions permit you to switch from model to paper space, if needed.  The data is kept in a global var.

 

;;;;;;;;;;;;;;
;; http://www.lee-mac.com/attributefunctions.html

;; Get Attribute Values  -  Lee Mac
;; Returns an association list of attributes present in the supplied block.
;; blk - [vla] VLA Block Reference Object
;; Returns: [lst] Association list of ((<tag> . <value>) ... )
(defun LM:vl-getattributevalues ( blk )
    (mapcar '(lambda ( att ) (cons (vla-get-tagstring att) (vla-get-textstring att))) (vlax-invoke blk 'getattributes))
)

;; Set Attribute Values  -  Lee Mac
;; Sets attributes with tags found in the association list to their associated values.
;; blk - [vla] VLA Block Reference Object
;; lst - [lst] Association list of ((<tag> . <value>) ... )
;; Returns: nil
(defun LM:vl-setattributevalues ( blk lst / itm )
    (foreach att (vlax-invoke blk 'getattributes)
        (if (setq itm (assoc (vla-get-tagstring att) lst))
            (vla-put-textstring att (cdr itm))
        )
    )
)

;;;;;;;;;;;;;;

(vl-load-com)

;; global variable that holds the data.
;; That means it's easy do push data, and pull it anytime later
(setq export_data (list))

;; Extract Import One by one, in a loop
;; select one source block, then select one destination block
(defun c:eio ( / item blk1 blk2)
  (while (setq blk1 (entsel "\nSource block: "))
    (setq blk2 (entsel "\nDestination block: "))
    (setq item (LM:vl-getattributevalues (vlax-ename->vla-object (car blk1) )))
    (LM:vl-setattributevalues (vlax-ename->vla-object (car blk2) ) item)
  )
  (princ)
)

;; Extract Multiple Blocks
;; First use emb to extract blocks.  Then use imb to import
(defun c:emb (/ blk1 item)
  (princ "\nSelect multiple blocks to extract data of.  Press enter to exit the loop.")
  (while (setq blk1 (entsel "\nSource block: "))
    (setq item (LM:vl-getattributevalues (vlax-ename->vla-object (car blk1) )))
    (setq export_data (append export_data (list item)))
  )
  (princ)
)

;; Import Multiple Blocks
;; First use emb to extract blocks.  Then use imb to import
(defun c:imb (/ blk2 item)
  (princ "\nSelect multiple blocks to import data to.  Press enter to exit the loop.")
  (while (setq blk2 (entsel "\nDestination block: "))
    (setq item (car export_data))
    (setq export_data (cdr export_data))
    (LM:vl-setattributevalues (vlax-ename->vla-object (car blk2)) item)
  )
  (princ)
)

 

 

copy_paste_attributes.dwg

Edited by Emmanuel Delay

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...