Lisp routine to draw wall combo

Lisp routine to draw wall combo

äcäp
Enthusiast Enthusiast
2,793 Views
17 Replies
Message 1 of 18

Lisp routine to draw wall combo

äcäp
Enthusiast
Enthusiast

Greetings all,

Pardon my English and knowledge as I know nothing about lisp nor coding in AutoCAD.

I just found a lisp routine somewhere on the net, to draw a Wall combo (wall complete with plastering and hatching) from one point to  another point, which I really interested with and found it very useful for my daily work use. Credits to whoever created this lisp 🙂

 

The lisp routine as below:

WALL(defun c:wall (/ pt1 pt2 pt3 pt4 pt5 pt6 pt7 pt8 len ang angt)
   (setvar "cmdecho" 0)
   (command "undo" "be")
   (initget 1)
   (setq pt1 (getpoint "\nChoose the wall starting point: "))
   (initget 1)
   (setq pt2 (getpoint pt1 "\nDetermine the wall length: "))
   (setq lama (getvar "osmode"))
   (setvar "osmode" 0)
   (setq ang (angle pt1 pt2))
   (setq len (distance pt1 pt2))
   (setq angt (angtos ang 4 4))
   (if (<= (* pi 25) ang)(setq angt (angtos (- ang (/ pi 2)) 4 4)))
   (setq pt3 (polar pt2 (+ (/ pi 2) ang) 150))
   (setq pt4 (polar pt3 (+ pi ang) len))
   (setq pt5 (polar pt1 (+ (/ pi 2) ang) 20))
   (setq pt6 (polar pt5 ang len))
   (setq pt7 (polar pt6 (+ (/ pi 2) ang) 110))
   (setq pt8 (polar pt7 (+ pi ang) len))
   (command "PLINE" pt1 pt2 pt3 pt4 "C")
   (command "PLINE" pt5 pt6 pt7 pt8 "C")
   (command "-HATCH" "P" "ansi37" "10" "0" "A" "A" "Y" "" "S" "last" "" "")
   (setvar "osmode" lama)
   (command "undo" "e")
)

 

I wonder if anyone can help me to refine the lisp, so the outcome will be as exacts as I expected. The original lisp routine will draw a wall combo  with very basic properties as all lines and hatching will be assigned to  Layer '0'.

I need the wall combo to have the option to specify wall thickness upon creation. Also each lines and hatching will be assigned with a specific layers and color automatically (kindly refer the screenshot below for further understanding).

 

Any help would be highly appreciated from the bottom of my heart. Many thanks in advance.

 

Wall-LSP.png

0 Likes
Accepted solutions (3)
2,794 Views
17 Replies
Replies (17)
Message 2 of 18

ec-cad
Collaborator
Collaborator
Accepted solution

Minus the Dim on right, but here's my take so far.

 

(defun c:wall (/ pt1 pt2 pt3 pt4 pt5 pt6 pt7 pt8 len ang angt)
   (setvar "cmdecho" 0)
   (command "undo" "be")
;; Setup Layers needed
   (setq curlayer (getvar 'clayer))
   (command "_layer" "M" "A-WALL" "")
   (command "_layer" "M" "A-H-WALL" "")
   (command "_layer" "M" "A-WALL-FINS" "")
   (command "_layer" "C" "RED" "A-WALL" "")
;;
   (initget 1)
   (setq pt1 (getpoint "\nChoose the wall starting point: "))
   (initget 1)
   (setq pt2 (getpoint pt1 "\nDetermine the wall length: "))
;;
   (setq thick (getdist "\nSpecify Wall Thickness")); added to obtain thickness
;;
   (setq lama (getvar "osmode"))
   (setvar "osmode" 0)
   (setq ang (angle pt1 pt2))
   (setq len (distance pt1 pt2))
   (setq angt (angtos ang 4 4))
   (if (<= (* pi 25) ang)(setq angt (angtos (- ang (/ pi 2)) 4 4)))
;   (setq pt3 (polar pt2 (+ (/ pi 2) ang) 150)); your original
   (setq pt3 (polar pt2 (+ (/ pi 2) ang) thick))
   (setq pt4 (polar pt3 (+ pi ang) len))
;   (setq pt5 (polar pt1 (+ (/ pi 2) ang) 20)); your original
   (setq pt5 (polar pt1 (+ (/ pi 2) ang) 20))
   (setq pt6 (polar pt5 ang len))
;   (setq pt7 (polar pt6 (+ (/ pi 2) ang) 110)); your original
   (setq pt7 (polar pt6 (+ (/ pi 2) ang) (- thick 40))); assumes 20 each side
   (setq pt8 (polar pt7 (+ pi ang) len))
   (setvar 'clayer "A-WALL-FINS")
   (command "PLINE" pt1 pt2 pt3 pt4 "C")
   (setvar 'clayer "A-WALL")
   (command "PLINE" pt5 pt6 pt7 pt8 "C")
   (setvar 'clayer "A-H-WALL")
   (command "-HATCH" "P" "ansi37" "10" "0" "A" "A" "Y" "" "S" "last" "" "")
   (setvar "osmode" lama)
   (setvar 'clayer curlay); reset original Layer
   (command "undo" "e")
   (princ)
); function wall

 

ECCAD

0 Likes
Message 3 of 18

Sea-Haven
Mentor
Mentor

Like this ? Not free but cheap has way more functions than just a wall.

 

SeaHaven_0-1729207660333.png

 

0 Likes
Message 4 of 18

Moshe-A
Mentor
Mentor
Accepted solution

@äcäp  hi,

 

check this CWALL command (Custom Wall)

the interface is similar to MLINE command.

 

Command: CWALL

Current settings: Justification = Top, Scale = 1.000, Fill = 70%
Specify start point or [Justification/Scale/Fill]:

 

the above is the command prompt.

 

Justification: has 3 options: Top, Zero, Bottom

Scale: refers to to wall width (in drawing units)

Fill: refers to hatch (ansi37) bar width. the default is 70% of wall width (allowed range 50% to 90%) do not enter '%' sign.

 

You can specify as many segment as needed (even undo in middle) including turns.

 

Bellow is 40 lines of top of the program, line# 33 defines the layers and Colors to create

if you want to change layers names or colors this is the place to do it.

 

Known Bug:

Some times the hatch comes thinner than specified and i do not know what the reason, it could be the screen/view distance or something else but it is not osnap. to overcome, invoke Undo and redo cwall.

 

enjoy

Moshe

 

(vl-load-com) ; load activex support

(defun c:cwall (/ _fill_ratio_check _fill_ratio_eval initial askJustify askReal askInt ; local functions
		  askPoint sharp_angle is_overlap is_inters duplicate_offset draw_bar  ; local functions
	          LAYERS justify scale fill ss0 p0 p1 points^ AcDbPLine)	       ; local variables

 ; anonymous functions
 (setq _fill_ratio_check (lambda (v) (and (>= v 50) (<= v 90))))
 (setq _fill_ratio_eval  (lambda () (* 1e-2 fill scale)))

 ; initial setup
 (defun initial ()
  (if (or
	(eq (getvar "users1") "")
	(not (member (getvar "users1") '("Top" "Zero" "Bottom")))
      )
   (setq justify (setvar "users1" "Top"))
   (setq justify (getvar "users1"))
  ); if

  ; for scale
  (if (eq (getvar "userr1") 0.0)
   (setq scale (setvar "userr1" 1.0))
   (setq scale (abs (getvar "userr1")))
  ); if
   
  ; for fill
  (if (not (_fill_ratio_check (getvar "useri2")))
   (setq fill (setvar "useri2" 70))
   (setq fill (abs (getvar "useri2")))
  ); if

  (setq LAYERS '(("a-wall-fins" . 9) ("a-wall" . 1) ("a-h-wall" . 252))) ; const
   
  ; create layers & colors
  (foreach lay LAYERS
   (if (null (tblsearch "layer" (car lay)))
    (command "._layer" "_new" (car lay) "_color" (cdr lay) (car lay) "")
   ); if
  ); foreach
 ); initial

0 Likes
Message 5 of 18

Sea-Haven
Mentor
Mentor

I like the idea of using Mline can make a mline style using lisp. This code could be changed for simpler size input. Or fixed sizes.

 

 

0 Likes
Message 6 of 18

äcäp
Enthusiast
Enthusiast

Nice!

This is the basic function that I need so far based on the original lisp  I posted earlier.

Thank you Sir!

0 Likes
Message 7 of 18

äcäp
Enthusiast
Enthusiast

This is even better. I tried normal MLINE command before and it does not really feed my needs.

I like the option where we can choose the Justification and Undo.

Any chance to set the fill/hatch to be Associative?

0 Likes
Message 8 of 18

äcäp
Enthusiast
Enthusiast

Thanks @Sea-Haven for the earlier suggestion.

However I tried the lsp attached and out of sudden, my ACAD freeze forever until I manually ended the task.

0 Likes
Message 9 of 18

Moshe-A
Mentor
Mentor

@äcäp ,

 

Any chance to set the fill/hatch to be Associative?

 

find these 2 lines at the bottom of the file, put them in comment

(command "._hatch" "ansi37" (* 0.1 scale) 0 "_si" "_Last")
(command "._chprop" "_si" "_Last" "_Layer" (caaddr LAYERS) "")

 

Replace them with this line:

(command "._-bhatch" "_Select" "_Last" "" "_Properties" "ansi37" (* 0.1 scale) 0 "_Layer" (caaddr LAYERS) "")

 

0 Likes
Message 10 of 18

äcäp
Enthusiast
Enthusiast

Great! The code you suggest works!

 

I just realise that the A-Wall-Fins line offset distance for the A-Wall line not consistent to 20 and it keeps changing when I key in the wall scale.

 

Same goes to Fill/Hatch scale as it uses ratio to fill in. Can we set these two issue to be consistent in the code?

0 Likes
Message 11 of 18

Moshe-A
Mentor
Mentor

@äcäp ,

 

Known Bug:

Some times the hatch comes thinner than specified and i do not know what the reason, it could be the screen/view distance or something else but it is not osnap. to overcome, invoke Undo and redo cwall.

 

Are you referencing to this?

 

0 Likes
Message 12 of 18

äcäp
Enthusiast
Enthusiast

Are you referencing to this?

 

Sorry @Moshe-A, I'm not very sure which 'thinner' you were referring to regarding the hatch, but my concern is on the hatch scale. 

I don't know how to explain in detail. Hope the screenshot attached will help giving some picture of what it should be.

 

Cwall-Rev.png

 

With the current lsp, the you shared, I can draw a wall combo but the distance between plaster and wall, and also the hatch scale will be vary depending on the wall scale I choose. 

 

What I'm hoping is when drawing a wall combo, the distance between plaster and wall will consistent at 20 (or can be specified just like the Wall Scale) and the hatch scale remain on some number, say scale 15 regardless any Wall Scale I choose.

 

🙂

0 Likes
Message 13 of 18

Moshe-A
Mentor
Mentor
Accepted solution

@äcäp ,

 

Program fixed, note the changes, hatch scale 15 to me looks like too dense.

 

enjoy

Moshe

 

0 Likes
Message 14 of 18

Sea-Haven
Mentor
Mentor

Prior comment removed. 

0 Likes
Message 15 of 18

äcäp
Enthusiast
Enthusiast

Perfect!

This is what I'm looking for. Just the term 'Plaster Width' that confuses me at first, but it's ok. I can adapt with it.

Now I can freely draw fast wall without need to do double work such as offset, hatching so do layer assigning.

Indeed I really enjoy your lisp @Moshe-A 😊 

Thanks You!

 

* I'm working in metric environment, the hatch scale 15 looks fine on my drawing 👌

0 Likes
Message 16 of 18

äcäp
Enthusiast
Enthusiast

@Sea-Haven 

I am drawing in true mm units but I don't really understand what you suggesting. Is it referring to Annotative?

Care to explain a little bit?

My apology.

0 Likes
Message 17 of 18

Moshe-A
Mentor
Mentor

Cheers, glad it is very useful 😀

Message 18 of 18

Sea-Haven
Mentor
Mentor

Misunderstood the comment about hatch scaling sorry about that.