Jump to content

Recommended Posts

Posted

Infil Panels-Layout1.pdfInfil Panels-Layout1.pdfInfil Panels-Layout1.pdfInfil Panels-Layout1.pdfInfil Panels-Layout1.pdfInfil Panels-Layout1.pdfHi All. I'm after some help with this pleasae.

I want to insert 4 blocks into my drawing to form a square shape. The original 4 entities  that I made are polylines and are saved as blocks in one drawing called BLOCKS_1.

I start a new drawing and insert  BLOCKS_1 into my drawing. This then makes the 4 polyline blocks available in my current drawing.

I am then inserting the 4 blocks each at their relative 0,0,0 point which arranges the blocks how I want them.

Heres where I cant get the join command to work. (I can manually join the 4 entities together using the JOIN command)

After inserting the 4 blocks I am exploding them so they are now polylines and their end points are touching to form a square.

this is an example of the code to only insert and explode 1 of the entities. I repeat this insert 3 more times, and change the ENTLAST to Ent2 Ent3 Ent4

 

(command "-insert" "Infil_HL" (0.0 0.0 0.0) "" "" "") ;Infil_HL is the block name one of the 4 entities thast are present in the drawing
(setq Ent1 (entlast))
(command "_explode" Ent1)

 

now when I run the join command it won't join the 4 entities into one.

 

(command "_join" Ent1 Ent2 Ent3 Ent4)

 

Regards Tony

Posted (edited)

little background on how DWG drawings work or how I understand. When you create or modify anything in a drawing it puts it at the end of drawing list. that is why you can select the last thing with (entlast) The blocks you are inserting is a made up of entity's and when you explode the block its gone but it's entity's are left in the drawing. even if its only one item its now under a different entity name. Your join command is saying join block 1 2 3 4 but you exploded them. you have to build another selection set of those entity's to join. so you create a place holder in the Drawing list with LastEnt insert and explode your block. then with the while its basically saying anything after this point in the list add to selection set SS. then pass the SS  to the join command.

 

(setq SS (ssadd))  
(setq LastEnt (entlast)) 
(command "-insert" "*Infil_HL" '(0.0 0.0 0.0) "" "" "")
(command "-insert" "*blk2" '(0.0 0.0 0.0) "" "" "") ;ent2
(command "-insert" "*blk3" '(0.0 0.0 0.0) "" "" "") ;ent3
(command "-insert" "*blk4" '(0.0 0.0 0.0) "" "" "") ;ent4
(while (setq LastEnt (entnext LastEnt))
  (ssadd LastEnt SS)
)
(command "_join" SS)

 

-edit 

adding * infront of the block name AutoCAD inserts and immediately explodes it in one step.

Edited by mhupp
  • Like 2
  • Thanks 1
Posted
5 hours ago, mhupp said:

adding * infront of the block name AutoCAD inserts and immediately explodes it in one step.

 

I didn't know that

  • Like 1
Posted

 @Steven P  I used it mostly for inserting text in blocks that need to be specific fonts,  spacing, layers , and color. a side note even tho the blocks are exploded they are in the block library until you purge. keep that in mind when using generic block names. pasting a block from a different drawing will pull from the block library instead if they have the same name not the clipboard. So if block1 is a circle in DrawingA and a square in DrawingB. Selecting the block in drawingA and copy paste into DrawingB when it paste all the blocks will be squares. not the circles you copied.

  • Like 1
Posted (edited)

I agree with @SLW210 why not just draw it, you just need to make a front end for input. This movie shows an example that is way more complex than your shape.

 

If you define the variables required like lengths A & B & C etc then a program could be done pretty quick. I have a Make a DCl lisp that could be used to make the front end input DCL.

 

It looks like Length & Height, Tab widths & offset from ends, Slot sizes. Pretty simple all objects would be plines. Oh yeah all dimmed.

 

It could also be made as a Dynamic block.

 

Why not have a go, good task about learning lisp, as basic shapes to be made.

 

 

Edited by BIGAL
Posted

Found some time have a look at this not finished but draws tabs. Save Multi getvals.lsp to a support path.

 

; https://www.cadtutor.net/forum/topic/98697-autocad-join-command/
; Draw tabs on a rectang
; By AlanH Sept 2025


(defun c:wow ( / oldsnap pt1 pt2 pt3 pt4 pt5 pt6 ssadd)

(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq ans (AH:getvalsm (list "Enter values " "length" 5 4 "200" "Width " 5 4 "200" "Tab height" 5 4 "20" "Tab width" 5 4 "20" "Tab edge dist" 5 4 "15")))
 
(setq len (atof (nth 0 ans))
ht (atof (nth 1 ans))
tabht (atof (nth 2 ans))
tabwid (atof (nth 3 ans))
tabedge (atof (nth 4 ans))
)

(setq pt1 (getpoint "\nPick point bottom left ")
 pt2 (mapcar '+ pt1 (list len 0.0 0.0))
 pt3 (mapcar '+ pt1 (list len ht 0.0))
 pt4 (mapcar '+ pt1 (list 0.0 ht 0.0))
)

(command "rectang" pt1 pt3)
(setq ent1 (entlast))

(setq pt5 (mapcar '+ pt1 (list 0.0 tabedge 0.0)))
(setq pt6 (mapcar '+ pt1 (list 0.0 (+ tabedge tabwid)  0.0)))
(command "Break" ent1 pt5 pt6 )
(setq pt7 (mapcar '+ pt5 (list (- (- tabwid (/ tabht 2.0))) 0.0 0.0)))
(setq pt8 (mapcar '+ pt6 (list (- (- tabwid (/ tabht 2.0))) 0.0 0.0)))
(setq mp (mapcar '* (mapcar '+ pt7 pt8) '(0.5 0.5)))
(command "pline" pt6 pt8 "a" pt8 "CE" mp pt7 "L" pt5 "")

(setq pt5 (mapcar '+ pt4 (list 0.0 (- tabedge) 0.0)))
(setq pt6 (mapcar '+ pt4 (list 0.0 (- (+ tabedge tabwid))  0.0)))
(command "Break" ent1 pt5 pt6 )
(setq pt7 (mapcar '+ pt5 (list (- (- tabwid (/ tabht 2.0))) 0.0 0.0)))
(setq pt8 (mapcar '+ pt6 (list (- (- tabwid (/ tabht 2.0))) 0.0 0.0)))
(setq mp (mapcar '* (mapcar '+ pt7 pt8) '(0.5 0.5)))
(command "pline" pt5 pt7 "a" pt7 "CE" mp pt8 "L" pt6 "")

(setq pt5 (mapcar '+ pt3 (list 0.0 (- tabedge) 0.0)))
(setq pt6 (mapcar '+ pt3 (list 0.0 (- (+ tabedge tabwid))  0.0)))
(command "Break" ent1 pt5 pt6 )
(setq pt7 (mapcar '+ pt5 (list (- tabwid (/ tabht 2.0)) 0.0 0.0)))
(setq pt8 (mapcar '+ pt6 (list (- tabwid (/ tabht 2.0)) 0.0 0.0)))
(setq mp (mapcar '* (mapcar '+ pt7 pt8) '(0.5 0.5)))
(command "pline" pt6 pt8 "a" pt8 "CE" mp pt7 "L" pt5 "")

(setq pt5 (mapcar '+ pt2 (list 0.0 tabedge 0.0)))
(setq pt6 (mapcar '+ pt2 (list 0.0 (+ tabedge tabwid)  0.0)))
(command "Break" ent1 pt5 pt6 )
(setq pt7 (mapcar '+ pt5 (list (- tabwid (/ tabht 2.0)) 0.0 0.0)))
(setq pt8 (mapcar '+ pt6 (list (- tabwid (/ tabht 2.0)) 0.0 0.0)))
(setq mp (mapcar '* (mapcar '+ pt7 pt8) '(0.5 0.5)))
(command "pline" pt5 pt7 "a" pt7 "CE" mp pt8 "L" pt6 "")

(setq topr (mapcar '+ pt3 (list (+ tabwid 1.0)  1.0 0.0)))
(setq botl (mapcar '+ pt1 (list (- (+ tabwid 1.0))  -1.0 0.0)))
(command "join" "w"  topr botl "")

(setvar 'osmode oldsnap)
(princ)
)

(c:wow)

image.png.4911a351bf4341a5dbe8da7cdab4bf16.pngimage.png.a92ec3840224b8fb26cbb0b393a5b1dc.png

Multi GETVALS.lsp

Posted

Slight different way of looking at this - back to OPs original problem of how to select the entities - instead of insert and explode, load the block into the drawing and grab the entities it contains from there. The block doesn't need to be inserted, that can come shortly.

 

This will insert the exploded block (for most simple entities, not tested fully)

 

The selection set MyAllSS contains all the inserted entities, so I think (command "join" .... ) will join everything together

 

You'll have to adjust the BlockName list.

 

(defun c:SSBlockEntities ( / BlockName acount MyEnts MyAllSS MySS MyEnt NewEnt)
;;Sub routines
;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-select-all-entities-inside-of-a-block/td-p/10284294
  (defun blockcomponents ( blk / ent rtn )
    (if (setq ent (tblobjname "block" blk))
        (while (setq ent (entnext ent))
            (setq rtn (cons ent rtn))
        )
    )
    (reverse rtn)
  )
;; End subroutines

  (setq BlockName '( "CircuitBreaker" "CT"))    ;; Block Names to assess
  (setq MyAllSS (SSAdd))                        ;; Blank Selection set - all entities, all blocks

  (foreach n BlockName
    (setq MySS (SSAdd))                         ;; Blank Selection set
    (setq acount 0)                             ;; A counter
    (setq MyEnts (blockcomponents n))           ;; Entity list for block
    (while (< acount (length MyEnts))           ;; Loop this block
      (setq MyEnt (entget (nth acount MyEnts))) ;; nth entity description
      (setq NewEnt (entmakex MyEnt))            ;; Make a new entity
      (ssadd NewEnt MySS)                       ;; Add entity to selection set
      (ssadd NewEnt MyAllSS)                    ;; Add entity to selection set - all entities, all blocks
      (setq acount (+ acount 1))                ;; Increase Loop
    ) ; end while
                 
;; Or do command 'Move' and 'rotate' on MySS selection set here:
    (command "move" MySS "" '(0 0 0) pause "")
    (command "rotate" MySS "" (getvar 'lastpoint) pause)

  )   ; foreach n
                    
  (princ) ; exit quietly
)

 

  • Like 1

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...