Lisp for inserting a blocks specific to a selection

Lisp for inserting a blocks specific to a selection

bgraverholt
Advocate Advocate
3,079 Views
12 Replies
Message 1 of 13

Lisp for inserting a blocks specific to a selection

bgraverholt
Advocate
Advocate

Looking to build a lisp that asks the user to selection blocks that are located in a legend and it will insert the detail blocks that is associated with each legend block line item. I attached 2 drawings one called XLS LEGEND and the other one called XLS DETAILS. Basically we insert the blocks from the tool palette for the legend and then have to go back through and insert the details for each device in the legend but if there was a way to insert the drawing XLS DETAILS and insert each block one by one automatically from the selected blocks that I have inserted for the legend? Then delete the XLS DETAILS dwg from the drawing? I hope this is possible! speed up inserting details. Let me know if I explain anything in more detail.

0 Likes
Accepted solutions (1)
3,080 Views
12 Replies
Replies (12)
Message 2 of 13

pbejse
Mentor
Mentor

@bgraverholt wrote:

Looking to build a lisp that asks the user to selection blocks that are located in a legend and it will insert the detail blocks that is associated with each legend block line item. ... 


This sounds interesting and fun to code, need more info though. However you can achieve all this [in conjuncton with Tool Palette] with Design Center.

 

Tell us more bgraverholt. show us a "real world" drawing sample. 

 

0 Likes
Message 3 of 13

bgraverholt
Advocate
Advocate

Here's a quick example. I haven't heard of using the tool palette like that I usually just click each detail in after I insert the legend.

0 Likes
Message 4 of 13

pbejse
Mentor
Mentor

@bgraverholt wrote:

Here's a quick example. 


What you had in mind is insert the block "XLS DETAILS.dwg" onto your drawing session and remove the blocks that does not corresponds with any legend?

So placement of the blocks is not important then?

 

Or would you rather invoke a command to select a particular legend then you'll be prompted for insertion point?

 

Or run a program to search for "legends" on the current drawing session and insert only the blocks corresponding with the legend?

 

Will you be using this for new drawings? 

 

I can think of more than one way to do this and i'm sure there are other ideas from other forum members. but you need to be clear from the get-go. 

 

BTW: is it too late to change the LEGEND blocks?

EDIT2: Do you normally have those blocks in one file? or mulitple blocks in one folder ?

0 Likes
Message 5 of 13

bgraverholt
Advocate
Advocate

Placement of the blocks are important for the reason that layouts are always different so placement of each block so it doesn't over lap the floor plan or other notes. So the best option that you put down would be select the legend blocks and prompt insertion points for each detail block. The drawing will be basically a new drawing it will have a floor plan with devices shown on the floor plan but thats it. The blocks are located in the first 2 files I attached to this post, XLS DETAILS and XLS LEGEND. Not sure what you mean by to late to change the legend blocks they can always be changed if needed to be.

0 Likes
Message 6 of 13

pbejse
Mentor
Mentor

@bgraverholt wrote:

So the best option that you put down would be select the legend blocks and prompt insertion points for each detail block. The drawing will be basically a new drawing it will have a floor plan with devices shown on the floor plan but thats it. The blocks are located in the first 2 files I attached to this post, XLS DETAILS and XLS LEGEND. 


Ok, done deal, i'll get back to you tomorrow, its late night here now. Stick around though, there might be someone else here writng a code as of this writing.

 

I'll check in later  Smiley Happy

 

Cheers

pBe

0 Likes
Message 7 of 13

pbejse
Mentor
Mentor
Accepted solution

Here's a draft

 

(defun c:ib ( / lst _insblock _BlockExist adoc lst leg bn blk ipoint dbx blkdbx)
;;;		pBe mar215		;;;
(defun _BlockExist (bn_ / indfile f)
  (cond
;;;	Current drawing session				;;;
    ((or (tblsearch "BLOCK" "XLS DETAILS")
	 (tblsearch "BLOCK" bn_)
     )
     bn_
    )
;;;	Block saved as individual file within SFSP	;;;
((setq indfile (findfile (strcat bn_ ".dwg"))) indfile)
;;; if found, copy listed blocks from ;;; ;;; "XLS DETAILS.dwg" will only run once per ;;; ;; session if other conditions evaluates to nil ;;;
((setq f (findfile "XLS DETAILS.dwg")) (if (< (atoi (substr (getvar "ACADVER") 1 2)) 16) (setq dbx (vlax-create-object "ObjectDBX.AxDbDocument")) (setq dbx (vlax-create-object (strcat "ObjectDBX.AxDbDocument." (substr (getvar "ACADVER") 1 2) ) ) ) ) (vla-open dbx f) (foreach itm (mapcar 'cadr lst) (if (not (vl-catch-all-error-p (vl-catch-all-apply (function (lambda () (setq blkdbx (vla-item (vla-get-blocks DBX) itm)) ) ) ) ) ) (vla-copyobjects DBX (vlax-safearray-fill (vlax-make-safearray vlax-vbObject '(0 . 0)) (list blkdbx) ) (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)) ) ) ) ) (vlax-release-object dbx) bn_ ) ) ) (setq adoc (vla-get-activedocument (vlax-get-acad-object))) ;;; Name of Legend/Block equivalent ;;; ;;; This list does not include all blocks ;;; (setq lst '(("HMS-D-LEGEND" "HMS-D-DETAIL") ("HTRI-D-LEGEND" "HTRI-D BASIC DETAIL") ("HTRI-R-LEGEND" "HTRI-R-DETAIL") ("SE-MC-CW" "SE-MC - SET-MC SPEAKER STROBE") ("FDBZ492-HR - OP921 - ST-50 LEGEND" "FDBZ492 - RSM-2 - HTRI-R - RL-HW") ("ZR-MC-R" "ZR-MC - ZH-MC - ZR-HMC") ("HFP-11 - DB-11" "SMOKE AND HEAT TYPICAL DETAIL")) ) (if (and (setq leg (car (entsel "\nSelect Legend: "))) (setq bn (cdr (assoc 2 (entget leg)))) (setq bn (cadr (assoc bn lst))) (setq bn (_BlockExist bn)) (setq ipoint (getpoint "\nPick point for block insertion: ")) ) (vlax-invoke (vlax-get (vla-get-ActiveLayout adoc) 'Block) 'InsertBlock ipoint bn 1 1 1 0) (princ "\n<<< Block Legend not found >>>")) (princ) )

 

Conditions:

 

The location of the file "XLS DETAILS.dwg" should be included within SFSP [Support File Search Path] 

 

This draft will support "EXAMPLE.dwg" posted by bgraverholt limited to current Legend and equivalent Detail on that particular file, additional pair can be incorporated on lst variable later 

 

The "XLS DETAILS.dwg" file should be close while nunning this code [however, the code can be modified to work regardles the file is open or close]

 

THREAD/POST reference:    vla-copyobjects 

 

HTH 

 

pBe

Message 8 of 13

bgraverholt
Advocate
Advocate

That's awesome work!!! It works!! Thank you I will have to have fun adding block names to the lisp file. Is there a way to have it do a mass selection? Such as do a cross selection of the legend and insert them one at a time? But have it only recognized blocks just in case you select a line or text. Then if there is a block that was selected and there is no associated detail for the legend block to list them in the command prompt and exclusions list since some legend items don't get details? 

0 Likes
Message 9 of 13

hmsilva
Mentor
Mentor

Nicely done, pBe!

 

Henrique

EESignature

0 Likes
Message 10 of 13

pbejse
Mentor
Mentor

@hmsilva wrote:

Nicely done, pBe!

 

Henrique


Cheers Henrique, to save time writing the draft i took the liberty of grabbing your snippet from another thread for vla-capyobject, so you have a hand on it more than you can tell Smiley Happy

 


@bgraverholt wrote:

That's awesome work!!! It works!! Thank you I will have to have fun adding block names to the lisp file....


You are welcome bgraverholt, Glad you like it. Smiley Happy Also kudos to Henrique

 


@bgraverholt wrote:

Is there a way to have it do a mass selection? Such as do a cross selection of the legend and insert them one at a time? But have it only recognized blocks just in case you select a line or text. Then if there is a block that was selected and there is no associated detail for the legend block to list them in the command prompt and exclusions list since some legend items don't get details? 


Sure there is, but what of the order of details to insert? 

 

**Yes we can do that too.

 

If you include ALL the legend block name from your XLS LEGEND.dwg and its assocaited detail, then there's no need produce an exclusion list on the command prompt, unless its just a reminder for the benefit of the user then we can do that too.

 

One thing i noticed though, it would have been better if the block names for the legend with associated detail all have the suffix of LEGEND ["FC922-UT LEGEND"], that will narrow down the **selection set , then theres no danger of selecting a non valid legend block name. but it still your call.

 

Also there are blocks on XLS DETAILS.dwg that has more than one legend symbol, does that mean if and only if those two legend symbols appear then insert the detail?

 

Come to think of it, we can even do it the other way around. insert the blocks [tool paelettes] then build the legend from the existing detail blocks on the drawing

 

Thouhgts?

 

pBe

 

 

0 Likes
Message 11 of 13

hmsilva
Mentor
Mentor

@pbejse wrote:

@hmsilva wrote:

Nicely done, pBe!

 

Henrique


Cheers Henrique, to save time writing the draft i took the liberty of grabbing your snippet from another thread for vla-capyobject, so you have a hand on it more than you can tell Smiley Happy


Cheers pBe!

Happy to be useful!  Smiley Happy

 

Henrique

 

EESignature

0 Likes
Message 12 of 13

bgraverholt
Advocate
Advocate

This Lisp has been amazing but I have came across a hiccup inserting 2 different blocks. I have 2 Image that I created each as a block so I can add it to  the IB command. But when it runs I get an error stating the following

 

Choose System [XLS/Edwards/Nurse] <XLS>:
Select objects: Specify opposite corner: 1 found
Select objects:
Pick insertion point:
<<< Detail Not Found >>>
<<< Detail Not Found >>>

 

So I am assuming it is because its referencing an image reference. The Image is saved in the same location as the drawing with the blocks. Is there a way to get this to work or do I have to just personally add these to the drawing manually?

0 Likes
Message 13 of 13

scot-65
Advisor
Advisor
Embed the image into a blank drawing and Save As that drawing
with the same name as the image.

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes