Lisp for hollow 3D square shapes

Lisp for hollow 3D square shapes

j_winkleman
Enthusiast Enthusiast
366 Views
8 Replies
Message 1 of 9

Lisp for hollow 3D square shapes

j_winkleman
Enthusiast
Enthusiast

I have tried using AI to create a lisp that creates hollow 3D square shapes, no luck.  The wall thickness does not come out correct and it only allows to sweep 1 object at a time.  Use to have a lisp years ago that did exactly what I needed, and cannot find it now.  That lisp asked for tube size, wall thickness, and a path or paths.  I have attached what AI created.  Any help would be greatly appreciated!

 

0 Likes
Accepted solutions (1)
367 Views
8 Replies
Replies (8)
Message 2 of 9

DGCSCAD
Collaborator
Collaborator
Accepted solution

Here's another approach generated via AI (lightly tested and tweaked):

 

(defun c:BOXSHELL ( / len wid hgt thk ent basept)

  ;; Center point of box (you can change to getpoint if you want to pick it)
  ;(setq basept '(0 0 0))
   (setq basept (getpoint "\nSelect point for Box placement."))

  ;; Prompt for box dimensions
  (setq len (getdist "\nEnter box length: "))
  (setq wid (getdist "\nEnter box width: "))
  (setq hgt (getdist "\nEnter box height: "))

  ;; Create the 3D box using Center + Length option
  ;; Command sequence:
  ;; BOX → Center → basept → Length → len → wid → hgt
  (command "_.BOX"
           "_C"
           basept
           "_L"
           len
           wid
           hgt
  )

  ;; Get the last created solid
  (setq ent (entlast))

  ;; Prompt for shell thickness
  (setq thk (getdist "\nEnter wall thickness for shell: "))

  ;; Use SOLIDEDIT → Body → Shell on that solid
  ;;
  ;; Command line equivalent:
  ;; _SOLIDEDIT
  ;;   Enter a solids editing option [Face/Edge/Body/Undo/eXit] <eXit>: _BODY
  ;;   Enter a body editing option [Imprint/seParate solids/Shell/cLean/Check/Undo/eXit] <eXit>: _SHELL
  ;;   Select solids: (select our box)  (then Enter)
  ;;   Enter shell offset distance: thk
  ;;
  (command "_.SOLIDEDIT"
           "_BODY"
           "_SHELL"
           ent
           ""
           thk
           ""
	   "x"
  )

  (princ "\n3D box created and shelled via SOLIDEDIT.")
  (princ)
)

 

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 3 of 9

j_winkleman
Enthusiast
Enthusiast

Close, but no cigar.   I'm still working with SHS AI lisp, but it cannot get it to get the wall thickness correct.

0 Likes
Message 4 of 9

Radwan-Almsora
Explorer
Explorer

To successfully create hollow 3D square shapes with custom wall thicknesses and handle multiple paths at once, you need an AutoLISP routine that generates both an outer and inner square profile, subtracts the inner from the outer, and loops through your selected paths.

 

The AutoLISP RoutineYou can copy and paste the following AutoLISP code into a new text file and save it as HollowSquareSweep.lsp.

(vl-load-com)

(defun c:HSS ( / tubeSize wallThk pathSet i pathEnt outerSqr innerSqr hollowReg)
  (setq tubeSize (getdist "\nEnter overall tube size (width): "))
  (setq wallThk (getdist "\nEnter wall thickness: "))
  
  (princ "\nSelect path(s) (Lines, Arcs, or Polylines): ")
  (setq pathSet (ssget))

  (if (and tubeSize wallThk pathSet)
    (progn
      (setvar "CMDECHO" 0)
      (command "_.UNDO" "_BEGIN")

      ;; 1. Draw Outer Square
      (setq pt1 (list 0 0 0))
      (setq pt2 (list tubeSize tubeSize 0))
      (command "_.RECTANGLE" "_NON" pt1 "_NON" pt2)
      (setq outerSqr (entlast))

      ;; 2. Draw Inner Square
      (setq pt3 (list wallThk wallThk 0))
      (setq pt4 (list (- tubeSize wallThk) (- tubeSize wallThk) 0))
      (command "_.RECTANGLE" "_NON" pt3 "_NON" pt4)
      (setq innerSqr (entlast))

      ;; 3. Create the Hollow Region
      (command "_.REGION" outerSqr innerSqr "")
      (setq hollowReg (ssget "_P"))

      ;; 4. Subtract Inner Region from Outer
      (command "_.SUBTRACT" (ssname hollowReg 0) "" (ssname hollowReg 1) "")
      (setq hollowReg (entlast))

      ;; 5. Sweep along the selected paths
      (setq i 0)
      (while (< i (sslength pathSet))
        (setq pathEnt (ssname pathSet i))
        (command "_.SWEEP" hollowReg "" pathEnt)
        (setq i (1+ i))
      )

      (command "_.UNDO" "_END")
      (setvar "CMDECHO" 1)
      (princ "\nSuccessfully created hollow 3D tubes!")
    )
  )
  (princ)
)
(princ "\nType HSS to run Hollow Square Sweep")
(princ)

 

To resolve your issue, you can enter here. 

How to automatically load LISP routines in AutoCAD products

0 Likes
Message 5 of 9

j_winkleman
Enthusiast
Enthusiast

Coming up with an error on this one.  It is creating the dimensioned shape, but not creating the 3D shape.  

Screenshot 2026-06-17 133435.png

0 Likes
Message 6 of 9

DGCSCAD
Collaborator
Collaborator

@j_winkleman wrote:

Close, but no cigar.   I'm still working with SHS AI lisp, but it cannot get it to get the wall thickness correct.


This doesn't provide enough information to form a solution.

 

What doesn't work?

Can you not provide a wall thickness?

Have you tried using the BOX command along with the SolidEdit -> Shell command?

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 7 of 9

Kent1Cooper
Consultant
Consultant

Your code in Message 1 does not account for the possibility of any running Object Snap mode(s), but parts of its operation would be subject to that.  Does it work right if you turn Osnap off?

Kent Cooper, AIA
0 Likes
Message 8 of 9

Sea-Haven
Mentor
Mentor

For me the front end. Can be used for circles also ignore say width.

SeaHaven_0-1781742281306.png

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq ans (AH:getvalsm (list "Enter values " "Height " 5 4 "100" "Width " 5 4 "100" "Thickness" 5 4 "2.5" )))

Just a comment, when you talk about walking along a path, there is no mention about if path is in 3D, if a say line has 3d points like 0,0,0 and 10,10,10 then its on a 3D angle so you need to rotate the two rectangs to be square to the path before doing the extrude. Basically there are two hollow tubes, square or rectangular only sqaure is mentioned. Need a UCS command maybe if not creating in just a plan view. If you just want a length of say a line then can use that as extrude height no path needed.

 

Also which point are you using on the rectang as the control point for the rectang ? A corner or say the midpoint of the rectang edge. This could be a choice.

 

Perhaps some more information or a sample dwg of what is required.

 

There is some good make steel shapes lisp out there with lots of world wide library shapes, eg "Wiseys steel shapes.lsp" do a google.

 

SeaHaven_1-1781743665278.png

Ps no code all done manually, but could be a lisp.

0 Likes
Message 9 of 9

Sea-Haven
Mentor
Mentor

This is very rough and needs further improvements like circular tubes. Its just a proof of concept @j_winkleman give it a try, make sure you save Multi getvals.lsp into a support path or edit the (load "multi getvals") to include full path use dbl back slash's \\.

 

The path at the moment is the center of the tube that can be changed.

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-for-hollow-3d-square-shapes/td-p/14169287

; make tube rectangs and extrude along a path
; By AlanH June 2026

(defun c:drawtube ( / ans d1 d2 end ent ept ht obj oldsnap pt start thick wid)
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(setvar 'thickness 0.0)
(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq ans (AH:getvalsm (list "Enter values " "Height " 5 4 "100" "Width " 5 4 "100" "Thickness" 5 4 "2.5" )))
(setq ht (atof (nth 0 ans)))
(setq wid (atof (nth 1 ans)))
(setq thick (atof (nth 2 ans)))
(setq ent (entsel "\nPick start point of path "))
(setq ept (cadr ent))
(setq obj (vlax-ename->vla-object (car ent)))
(setq start (vlax-curve-getstartPoint obj))
(setq end (vlax-curve-getEndPoint obj))
(setq d1 (distance ept start))
(setq d2 (distance ept end))
(if (> d1 d2)
    (progn 
      (setq temp start)
      (setq start end)
      (setq end temp)
    )
)
(command "ucs" "OB" ent)
(setq pt '(0 0 0))
(command "rectang" 
 (mapcar '+ pt (list (/ (- wid) 2.0) (/ (- ht) 2.0) 0.0))
 (mapcar '+ pt (list (/ wid 2.0) (/ ht 2.0) 0.0))
)
(command "rotate3d" (entlast) "" "Y" '(0 0 0) 90)
(command "extrude" (entlast) "" "P" (car ent))
(setq ent1 (entlast))
(command "rectang" 
 (mapcar '+ pt (list (/ (- (- wid thick)) 2.0) (/ (- (- ht thick)) 2.0) 0.0))
 (mapcar '+ pt (list (/ (- wid thick) 2.0) (/ (- ht thick) 2.0) 0.0))
)
(command "rotate3d" (entlast) "" "Y" '(0 0 0) 90)
(command "extrude" (entlast) "" "P" (car ent))
(setq ent2 (entlast))
(command "subtract" ent1 "" ent2 "")
(command "UCS" "W")
(setvar 'osmode oldsnap)
(princ)
)
(c:drawtube)

 

Expect a couple of problems did very little testing. 

0 Likes