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
Posted

Hi All. This time I have included my files to give you a better idea of what i'm trying to acheive

Thanks for the ideas. I have used the PEDIT approach and it has almost worked. It joins 3 of the entities but not the 4th. The program runs right through.

Any ideas why the 4th entity won't join??

Ive included my DWG file for you to have a look and also my lisp routine. The bulk of the routine works well its just the join command

 

Regards

tony

Horozontal Infil.lsp Infil Panels AutoLisp Test.dwg

Posted (edited)

Read up on cond. better way to test/decide what block to insert. 

 

(cond 
  ((and (>= dist1 145) (< dist1 220))
    (command "-insert" "*Infil_sq_1" p7 "" "" "")
  )
  ((and (>= dist1 220) (< dist1 295))
    (command "-insert" "*Infil_sq_2" p7 "" "" "")  
  )
  ((and (>= dist1 295) (< dist1 370))
    (command "-insert" "*Infil_sq_3" p7 "" "" "")
  )
  ...
  ((and(>= dist1 1195) (< dist1 1270))
    (command "-insert" "*Infil_sq_15" p7 "" "" "")
  )
  (T ;if all other condtions fail
    (alert "\nDistance Greater than 1270")
  ) 
)

 

Edited by mhupp
  • Like 1
Posted
9 hours ago, delta said:

Hi All. This time I have included my files to give you a better idea of what i'm trying to acheive

Thanks for the ideas. I have used the PEDIT approach and it has almost worked. It joins 3 of the entities but not the 4th. The program runs right through.

Any ideas why the 4th entity won't join??

Ive included my DWG file for you to have a look and also my lisp routine. The bulk of the routine works well its just the join command

 

Regards

tony

Horozontal Infil.lsp 3.07 kB · 3 downloads Infil Panels AutoLisp Test.dwg 332.78 kB · 5 downloads

Please upload this defun 

(savevartoold) (infilpanellayer)

 

Posted
10 hours ago, delta said:

Hi All. This time I have included my files to give you a better idea of what i'm trying to acheive

Thanks for the ideas. I have used the PEDIT approach and it has almost worked. It joins 3 of the entities but not the 4th. The program runs right through.

Any ideas why the 4th entity won't join??

Ive included my DWG file for you to have a look and also my lisp routine. The bulk of the routine works well its just the join command

 

Regards

tony

Horozontal Infil.lsp 3.07 kB · 3 downloads Infil Panels AutoLisp Test.dwg 332.78 kB · 5 downloads

 use this PEDIT WAY 

 

(command "._PEDIT" topline "_J" "all" "" "" )  ;topline infilHL bottomline infilHR "" "_j" "" "")	 

 

Posted
2 hours ago, devitg said:

Please upload this defun 

(savevartoold) (infilpanellayer)

 

You can null these 2 defuns

Posted
2 hours ago, devitg said:

 use this PEDIT WAY 

 

(command "._PEDIT" topline "_J" "all" "" "" )  ;topline infilHL bottomline infilHR "" "_j" "" "")	 

 

Thank you very much. That works perfectly

Posted
6 hours ago, mhupp said:

Read up on cond. better way to test/decide what block to insert. 

 

(cond 
  ((and (>= dist1 145) (< dist1 220))
    (command "-insert" "*Infil_sq_1" p7 "" "" "")
  )
  ((and (>= dist1 220) (< dist1 295))
    (command "-insert" "*Infil_sq_2" p7 "" "" "")  
  )
  ((and (>= dist1 295) (< dist1 370))
    (command "-insert" "*Infil_sq_3" p7 "" "" "")
  )
  ...
  ((and(>= dist1 1195) (< dist1 1270))
    (command "-insert" "*Infil_sq_15" p7 "" "" "")
  )
  (T ;if all other condtions fail
    (alert "\nDistance Greater than 1270")
  ) 
)

 

Thank you for your advice

  • Like 1
Posted

I still think much easier to just select a line or pline near an end, then draw the tab based on some sort of sizes criteria, after doing the code i realised only really need one draw tab portion so can be on any segment and a bonus at any angle of the selected P/Line. The tab would be drawn and a simple flip to set it to inside or outside. You can pick say 4 times very fast. Even shapes would work.

 

Why not just have the tab as a block, much easier to work with. Will have a think about it. Oh yeah I think the infill can be done as an array rather than having lots of blocks.

 

Found your post over at forums/autodesk as well.

Posted (edited)

Please have a look at this, it makes a rectang then you can add the "TAB" to any side, even on an angle. The red points are the pick points working in a clock wise direction, if you pick wrong end the TAB will go inwards. I made a Block called " TAB" and used your dwg to set the edge distances. I did adjust the block ever so slightly it had like 33.70123  so set it to 33.7. here is also your dwg with the TAB block added. If your happy will add the Squares, again based on the rectang size.

 

image.png.8ae791d70541133862f2ec2e37e75e9e.png

 

(defun c:wow ( / oldsnap pt1 pt2 pt3 pt4 ang tabwid)

(setq oldsnap (getvar 'osmode))
(setq oldang (getvar 'aunits))

(setq ht 800.0 tabedge 41.0 tabwid 33.7)
(setq pt1 (getpoint "\nPick 1st point "))
(setq len (getdist pt1 "\nPick 2nd point "))

(setq  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))
)

(setvar 'osmode 0)
(setvar 'aunits 3)
 
(command "Line" pt1 pt2 pt3 pt4 "c") 

(while (setq ent (entsel "\nPick near start end - Enter to stop "))
(setq ept (cadr ent))
(setq ent (car ent))
(setq entg (entget ent))
(setq start (cdr (assoc 10 entg)))
(setq end (cdr (assoc 11 entg)))
(setq len2 (distance start end))
(setq d1 (distance ept start))
(setq d2 (distance ept end))
(if (> d1 d2)
    (progn 
      (setq temp start)
      (setq start end)
      (setq end temp)
    )
)

(setq ang (angle start end))
(setq pt5 (polar start ang tabedge))
(setq pt6 (polar pt5 ang tabwid))
(command "break" ent pt5 pt6)
(command "insert" "TAB" pt5 1 1  ang)
(command "explode" (entlast))

(setq pt5 (polar start ang (- len2 tabwid tabedge )))
(setq pt6 (polar pt5 ang tabwid))
(command "break" ent pt5 pt6)
(command "insert" "TAB" pt5 1 1 ang)
(command "explode" (entlast))
)

(setq pt3 (mapcar '+ pt3 (list 40 40 0.0)))
(setq pt1 (mapcar '+ pt1 (list -40 -40 0.0)))
(command "join" "w" pt3 pt1 "")

(setvar 'osmode oldsnap)
(setvar 'aunits oldang)

(princ)
)

(c:wow)

 

The array does have a pattern so your multi if's could become  as simple, as (fix (- (/ length 75) 1)) just try it. Vertical rows is 9 for 800.

 

(setq col (fix (- (/ 1220.234 75) 1)))

(setq bname (strcat "*Infil_sq_" (rtos col 2 0)))

 

Is the length overall or the distance between the centre points of the slots. Can fix length to match. Need you to confirm what this length is based on.

Infil Panels AutoLisp Test-TAB.dwg

Edited by BIGAL

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