Jump to content

Wall LISP Request.


TheNewGuy

Recommended Posts

Well Lee Mac I have another Lisp I was hoping you could help me with. :oops:This one is not for work, but will be a fathers day present. My dad is a contractor and a real estate agent. He was recently introduced to the world of autocad from me, and will be using it mostly to draw basic buildings. So I was looking for a way to automatically create walls with the studs inserted at the correct place and extruded to the correct height and all that. I have searched the internet and could only find reference to other people looking for the same thing. So if you create this lisp I think others would use it as well. What I am picturing in my head is a lisp that askes the user for some information about the wall and then draws it for them.

I picture the Lisp going something like this....

start lisp.

Ask for start point.

ask for wall length

ask for wall height.(extrud height)

ask for stud dimensions(length/width)

ask for stud spacing.(always on center from first stud..see example...)

Ask for sheet thickness("F" in example)

Ask for wall oriantation(0 degrees in example)

ask for side of start line wall should be built out from.(user would click on the screen... either right side, or left side of the start line..)

 

I have attached an example, so to speak but I have a feeling some further explanation will be required....:D Thank you so much for your time. You know I really appretiate all your hard work! And I am serious, I belive that others would find this lisp very helpfull too! (I belive ReeMark was looking for somthing like this back in October.) Any way let me know what doesn't make sense....

Wall Lisp example.dwg

Link to comment
Share on other sites

This is quite a task - definitely "do-able" but, very tedious and not pretty.

 

I think it would be good to use DCL for this kind of LISP also.

Link to comment
Share on other sites

Yea, I would have loved to do it myself because of the whole fathers day "gift" thing but I quickly realized I could not do it. What is DCL? Is it something I might be able to do?

Link to comment
Share on other sites

Yea, I would have loved to do it myself because of the whole fathers day "gift" thing but I quickly realized I could not do it. What is DCL? Is it something I might be able to do?

Just upgrade to Autodesk Architecture. This feature exist, plus a million other options and styles for very intricate architectural designs.

Link to comment
Share on other sites

Here is something to get you started. It creates the 2D but it could be fixed to create everything in 3D.

 

Feel free to bash the heck out of it.

 

;;; ------------------------------------------------------------------------
;;;    PLAN_STUDWALL.lsp v1.0
;;;
;;;    Copyright © December, 2006
;;;    Timothy G. Spangler
;;;
;;;    Permission to use, copy, modify, and distribute this software
;;;    for any purpose and without fee is hereby granted, provided
;;;    that the above copyright notice appears in all copies and
;;;    that both that copyright notice and the limited warranty and
;;;    restricted rights notice below appear in all supporting
;;;    documentation.
;;;
;;;    THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
;;;    WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
;;;    PURPOSE AND OF MERCHANTIBILITY ARE HEREBY DISCLAIMED BY THE
;;;    PROGRAMMER.
;;;
;;; -----------------------------------------------------------------------
(defun c:STUDWALL (/)(STUD_WALL "CMD" nil nil nil))

(defun STUD_WALL (RunType StudSize StudSpace DryWall / *error* OldClayer OldCmdEcho OldLunits OldLuPrec ActiveDoc Space StudSize StartPoint EndPoint StudSpace WallLength WallAngle Angle-180 Angle+90 Width Length NoStuds )
 
 ;;; Begin Error Handler -------------------------------------------------
(defun *error* (MSG)

	(if (not (member MSG '("Function cancelled" "quit / exit abort")))
		(princ (strcat "\n*** Program Error: " (strcase MSG) " ***"))
		(princ "\n... Program Cancelled ...")
	)
	(while (< 0 (getvar "cmdactive"))
		(command)
	)
	;; Reset environment varialbes
	(STUDWALL_RESET_ENV)
)
;;; End Error Handler ---------------------------------------------------
(STUDWALL_SET_ENV)
)
;;; ------------ SET ENVIROMENT BEFORE LAUNCH
(defun STUDWALL_SET_ENV(/)

(setq OldClayer (getvar "CLAYER"))
(setq OldCmdEcho (getvar "CMDECHO"))

(setvar "CMDECHO" 0)
(command "_undo" "BE")

(setq	ActiveDoc	(vla-get-activedocument (vlax-get-acad-object)))
(setq Space
	(if (= (getvar "cvport") 1)
		(vla-get-paperspace ActiveDoc)
		(vla-get-modelspace ActiveDoc)
	)
)
;; Create framing layer
(STUD_CREATE_LAYER "A-FRAM-WALL" "Framing Plan - Wall framing linework" "Continuous" "25" "157" "0")
(setvar "CLAYER" "A-FRAM-WALL")

;; Create wall
(if (= RunType "CMD")
	(RUN_STUDWALL)
	(GET_STUD_POINTS StudSize StudSpace DryWall)
)
)
;;; ------------ RUN STUDWALL
(defun RUN_STUDWALL (/)

;; Get wall thickness
(initget 1 "4 6 8")
(setq StudSize (getkword " \nEnter wall Thickness: (4=2x4/6=2x6/8=2x8)"))

;; Get stud spacing
(while (< (setq StudSpace (getreal " \nEnter stud spacing: "))6.0)
	(alert " Stud spacing Needs to be greater than 6\" ")
)			

;; Get drywall
(initget 1 "Yes y Y No n N")
(setq DryWall (strcase (getkword " \nAdd drywall?: (Yes/No)")))

(GET_STUD_POINTS StudSize StudSpace DryWall)
)
(defun GET_STUD_POINTS (StudSize StudSpace DryWall /)

;; Create stud block
(CREATE_STUD StudSize)

;; Define start and end points
(setq StartPoint (getpoint " \nDefine Start point for studwall: "))
(setq EndPoint (getpoint StartPoint " \nDefine end point for studwall: "))	

;; Set wall variables
(setq WallLength (distance StartPoint EndPoint))
(setq WallAngle (angle StartPoint EndPoint))	
(setq Angle-180 (- WallAngle (DTR 180)))
(setq Angle+90 (+ WallAngle (DTR 90)))

;; Justify start and end points
(setq StartPoint (polar StartPoint Angle+90 (/ Width 2)))
(setq EndPoint (polar EndPoint Angle+90 (/ Width 2)))

;; Create the wall
(CREATE_STUDWALL)
)
;;; ------------ CREATE STUDWALL
(defun CREATE_STUDWALL ( / Point Temp DWallLine1 DWallLine2 WallLine1 WallLine2 WallCenter WallEnd1 WallEnd2)

;; Create first stud
(INSERT_STUD BlockName (polar StartPoint WallAngle (/ Length 2)) WallAngle)

;; Count the number of studs
(setq NoStuds 1)

;; Create intermediate studs
(setq Point StartPoint)
(setq Temp (- WallLength 3))
(while (> Temp StudSpace)
	(setq Point (polar Point WallAngle StudSpace))
	(INSERT_STUD BlockName Point WallAngle)
	(setq Temp (- Temp StudSpace))
	
	;; Add to the stud count
	(setq NoStuds (1+ NoStuds))
)

;; Create last stud
(INSERT_STUD BlockName (polar EndPoint Angle-180 (/ Length 2)) WallAngle)

;; Add to the stud count
(setq NoStuds (1+ NoStuds))

;; Create wall lines
(setq WallCenter (vlax-invoke Space 'addline StartPoint EndPoint))
(setq WallLine1 (car (vlax-invoke WallCenter 'offset (/ Width 2))))
(setq WallLine2 (car (vlax-invoke WallCenter 'offset (-(/ Width 2)Width))))

;; Delete centerline
(vlax-invoke WallCenter 'delete)

;; Add drywall
(if (= DryWall "YES")
	(progn
		(setq DWallLine1 (car (vlax-invoke WallLine1 'offset 0.5)))
		(setq DWallLine2 (car (vlax-invoke WallLine2 'offset -0.5)))
		(setq WallEnd1 (vlax-invoke Space 'addline (vlax-get DWallLine1 'Startpoint)(vlax-get DWallLine2 'Startpoint)))
		(setq WallEnd2 (vlax-invoke Space 'addline (vlax-get DWallLine1 'Endpoint)(vlax-get DWallLine2 'Endpoint)))
	)
	(progn
		(setq WallEnd1 (vlax-invoke Space 'addline (vlax-get WallLine1 'Startpoint)(vlax-get WallLine2 'Startpoint)))
		(setq WallEnd2 (vlax-invoke Space 'addline (vlax-get WallLine1 'Endpoint)(vlax-get WallLine2 'Endpoint)))
	)
)

;; Send stud count
(princ (strcat "\nThere are " (rtos NoStuds 5 0)" studs in the wall."))

;; Reset environment varialbes
(STUDWALL_RESET_ENV)
)
;;; ------------ LAYER CREATION ROUINE
(defun STUD_CREATE_LAYER (Layer Descpition Linetype Thickness Color Plot / TmpList VLA-Obj)

;; Check to see if linetype exsists
(if (= (tblsearch "ltype" Linetype) nil)		
	(if (STUD_CHECK_LINETYPE (findfile "acad.lin") Linetype)
		(command "linetype" "load" Linetype "acad.lin" "")
		(setq Linetype "Continuous")
	)
)
;;; ------------ CREATE A LIST FOR ENTMAKE
(setq TmpList
	'((0 . "LAYER")
	(100 . "AcDbSymbolTableRecord")
	(100 . "AcDbLayerTableRecord")
	(70 . 0)
	)
	)
	;; Create layer name list
	(setq TmpList (append TmpList (list (cons 2 Layer))))
	;; Create layer color list
	(setq TmpList (append TmpList (list (cons 62 (atoi Color)))))
	;; Create layer linetype list
	(setq TmpList (append TmpList (list (cons 6 Linetype))))
	;; Create layer lineweight list
	(setq TmpList (append TmpList (list (cons 370 (atoi Thickness)))))
	;; Create layer plot list
	(setq TmpList (append TmpList (list (cons 290 (atoi Plot)))))
	;; Create layer from first item in the list
	(entmake TmpList)      
	;; Create layer description
	(if(or(= 16.1 (atof(getvar "acadver")))(< 16.1 (atof(getvar "acadver"))))
	(progn
	(setq VLA-Obj(vla-Add (vla-Get-Layers ActiveDoc)Layer))
	(vla-Put-Description VLA-Obj Descpition)
	(vlax-release-object VLA-Obj)
	)
)
)
;;; ------------ CHECKS TO SEE IF A LINETYPE IS AVAILIBLE
(defun STUD_CHECK_LINETYPE (LINFile Linetype / OpenFile LineNumber CurrentLine Result)

(setq OpenFile (open LINFile "r"))
(while (setq CurrentLine (read-line OpenFile))
	(if (wcmatch CurrentLine "`**")
		(progn				
			(setq LinetypeName (substr(car(TGS:Stringtolist CurrentLine ","))2))
			(if (= (strcase Linetype) LinetypeName)
				(setq Result T)
			)
		)
	)
)
(close OpenFile)
Result
)
;;; ------------ STRING TO LIST SUB ROUTINE
(defun TGS:StringToList (Stg Del / CurChr PosCnt TmpLst TmpStr)

(setq PosCnt 1
			TmpStr ""
)
(repeat (1+ (strlen Stg))
	(setq CurChr (substr Stg PosCnt 1))
	(if (= CurChr Del)
		(progn
			(setq TmpLst (cons TmpStr TmpLst))
			(setq TmpStr "")
		)
		(setq TmpStr (strcat TmpStr CurChr))
	)
	(setq PosCnt (1+ PosCnt))
)
(setq TmpLst (reverse TmpLst))
)
;;; ------------ INSERT STUD BLOCK SUB
(defun INSERT_STUD (BlockName InsPoint RotAngle /)

(entmake 
	(list 
		(cons 0 "INSERT") ;***
		(cons 2 BlockName) ;***
		(cons 6 "BYLAYER")
		;(cons 8 "0") ;Layer name
		(cons 10 InsPoint) ;***
		(cons 39 0.0)
		(cons 41 1.0)
		(cons 42 1.0)
		(cons 43 1.0)
		(cons 44 0.0)
		(cons 45 0.0)
		(cons 50 RotAngle)
		(cons 62 256)
		(cons 70 0)
		(cons 71 0)
		(cons 210 (list 0.0 0.0 1.0))
	)
)
)							 
;;; ------------ CREATE STUD BLOCK SUB - DOES NOT INSERT BLOCK
(defun CREATE_STUD (StudSize /)

(setq OldLunits (getvar "LUNITS"))
(setq OldLuPrec (getvar "LUPREC"))
(setvar "LUNITS" 2)
(setvar "LUPREC" 1)
(cond
	((= StudSize "4")(setq BlockName "2x4")(setq Length 1.5)(setq Width 3.5))
	((= StudSize "6")(setq BlockName "2x6")(setq Length 1.5)(setq Width 5.5))
	((= StudSize "8")(setq BlockName "2x8")(setq Length 1.5)(setq Width 7.5))
)

(if (= (tblsearch "block" BlockName) nil) 
	(progn 
		(entmake
			(list
				(cons 0 "BLOCK")
				(cons 2 BlockName)
				(cons 70 64)
				(cons 10 (list 0.0 0.0 0.0))
				(cons 8 "0")
			)
		)
		;; Left Side Line
		(entmake
			(list
				(cons 0 "LINE")
				(cons 10 (list (- (/ Length 2) Length) (- (/ Width 2) Width) 0.0))
				(cons 11 (list (- (/ Length 2) Length) (/ Width 2) 0.0))
				(cons 8 "0")
				(cons 62 256)
			)
		)
		;; Bottom Line
		(entmake
			(list
				(cons 0 "LINE")
				(cons 10 (list (- (/ Length 2) Length) (- (/ Width 2) Width) 0.0))
				(cons 11 (list (/ Length 2) (- (/ Width 2) Width)  0.0))
				(cons 8 "0")
				(cons 62 256)
			)
		)
		;; Right Side Line
		(entmake
			(list
				(cons 0 "LINE")
				(cons 10 (list (/ Length 2) (- (/ Width 2) Width)  0.0))
				(cons 11 (list (/ Length 2) (/ Width 2)  0.0))
				(cons 8 "0")
				(cons 62 256)
			)
		)
		;; Top Line
		(entmake
			(list
				(cons 0 "LINE")
				(cons 10 (list (/ Length 2) (/ Width 2)  0.0))
				(cons 11 (list (- (/ Length 2) Length) (/ Width 2) 0.0))
				(cons 8 "0")
				(cons 62 256)
			)
		)
		;; Left Cross
		(entmake
			(list
				(cons 0 "LINE")
				(cons 10 (list (- (/ Length 2) Length) (/ Width 2) 0.0))
				(cons 11 (list (/ Length 2) (- (/ Width 2) Width)  0.0))
				(cons 8 "0")
				(cons 62 
			)
		)
		;; Right Cross
		(entmake
			(list
				(cons 0 "LINE")
				(cons 10 (list (- (/ Length 2) Length) (- (/ Width 2) Width) 0.0))
				(cons 11 (list (/ Length 2) (/ Width 2)  0.0))
				(cons 8 "0")
				(cons 62 
			)
		)
		;; Endblock
		(entmake
			'((0 . "ENDBLK"))
		) 
	)
	(princ "\n\n Block found in drawing")
)
(setvar "LUNITS" OldLunits)
(setvar "LUPREC" OldLuPrec)
BlockName
)
;; ------------ DEGREES / RADIANS SUB ROUTINES
(defun DTR (NumberOfDegrees) 
(* pi (/ NumberOfDegrees 180.0))
)
;;; ------------ RESET SYSEM VARIABLES
(defun STUDWALL_RESET_ENV (/)

(command "_undo" "End")
(setvar "CMDECHO" OldCmdEcho)
(setvar "CLAYER" OldClayer)
(princ)	
)
;;;
;;; Echos to the command line
(princ "\n CreateStudWall v1.0 ©Timothy Spangler, \n  December, 2006....loaded.")
(terpri)
(princ "Type \"STUDWALL\" to begin")
(print)
;;; End echo

Link to comment
Share on other sites

What is DCL? Is it something I might be able to do?

 

DCL = "Dialog Control Language"

 

Check these out as an example:

http://www.cadtutor.net/forum/showthread.php?t=35234

http://www.cadtutor.net/forum/showthread.php?t=33919

Input is then not restricted to the command line.

 

But I think this is a lot of hassle for something that could be accomplished easily either using software as Styk suggests, or narrowing it down to a LISP that just calculates the number of studs you need.

 

I might add that I am not the only member of this forum and that this is a help and advice site. Remember that I am volunteering my time to help others without any remuneration - I very much doubt that you would find many people willing to spend a lot of time writing a program for you, without any form of repayment. The members on this site are not here to serve you, but to offer advice. I realise that I have written a few requested programs in the past, but I must draw a line on how much time is consumed on such programs.

Link to comment
Share on other sites

Yes, I guess this is not such a good idea. please remember that to me they all seem complicated an yet you can create them in minutes. That is why I felt that I could at least ask.

I might add that I am not the only member of this forum and that this is a help and advice site. Remember that I am volunteering my time to help others without any remuneration - I very much doubt that you would find many people willing to spend a lot of time writing a program for you, without any form of repayment. The members on this site are not here to serve you, but to offer advice. I realise that I have written a few requested programs in the past, but I must draw a line on how much time is consumed on such programs.
I understand, Thank you for the work you have done in the past. Also, I agree with you that not many would be willing to do what you have done, and I do appreciate it very much! I apologize if I have over stepped my bounds.:oops: please accept my apology. I will explore other options and continue to teach myself so that I can write programs for myself and hopefully for others like you have done for me.:D
Link to comment
Share on other sites

Thank you Tim Spangler, the code you posted is a great starting point. It is almost exactly what I was picturing in my head. I searched for something like this but did not find it prior to posting. I guess I did not look hard enough! Thank you!

Also, I will look into acad architectural it does appear to be what my father would need. Thanks for every ones input.

Link to comment
Share on other sites

please remember that to me they all seem complicated an yet you can create them in minutes. That is why I felt that I could at least ask.

What you are requesting I highly doubt takes minutes. Way more than that.

Link to comment
Share on other sites

What you are requesting I highly doubt takes minutes. Way more than that.

I realize that now, he wrote a lisp for me in the past that I thought would be very difficult and he seemed to make it in minutes. That is what I was referring to.

However, I have said that I understand he must draw a line somewhere and I agree. He is volunteering his time and is helping many, many people. I am not offended and will try to do a better job limiting my requests in the future. I am still very appreciative for all the help and advice that can be found at this forum. Thank you to everyone for all your help!

Here is one from the late '90s that I wrote. Compurserve days wow. -David

This is a very complex program! well done. Thank you for your help!

I think I have what I need and I believe my father will be very happy with these programs. Thanks again.

Link to comment
Share on other sites

I realize that now, he wrote a lisp for me in the past that I thought would be very difficult and he seemed to make it in minutes.

 

Things that take a long time by hand can sometimes be very quick to write into LISP, however, in this instance - a LISP to create what you are requesting would be very tedious to write due to the number of variables involved.

 

I only published that comment in the last post as the thread seemed to be directly addressed to me - and, although I have helped in the past, this forum is open to everyone :)

Link to comment
Share on other sites

I understand, addressing it to you was my weak attempt at humor, and did not translate very well in type..... Thank you for your reply. I guess I needed more....... and :):oops::D:huh: to make it funny! any way the lisp's posted by the other user are great!

Thanks again for your time.

Link to comment
Share on other sites

For my five cents worth I worked for a company and we wrote and sold a simple architectural add on prior to Architectural desktop it took around 2 years to write it to a sellable product it would do simple house plans in 3d, multiple wall styles internal-external, roofs, doors, windows, stairs automatic dimensioning etc

 

Here is the start up menu with a wall input example the answers were saved into the drawing.

 

Search forums etc there is a lot of free stuff out there.

CADARC.JPG

  • Like 1
Link to comment
Share on other sites

  • 7 years later...
Here is one from the late '90s that I wrote. Compurserve days wow. -David

 

hi david

 

when i use your lisp in autocad suddenly was happened the autocad has stopped working. why i don't know . could you solve it. it will be really appreciate.

 

best regards

 

thajmul hussain

Link to comment
Share on other sites

Here is something to get you started. It creates the 2D but it could be fixed to create everything in 3D.

 

Feel free to bash the heck out of it.

 

;;; ------------------------------------------------------------------------
;;;    PLAN_STUDWALL.lsp v1.0
;;;
;;;    Copyright © December, 2006
;;;    Timothy G. Spangler
;;;
;;;    Permission to use, copy, modify, and distribute this software
;;;    for any purpose and without fee is hereby granted, provided
;;;    that the above copyright notice appears in all copies and
;;;    that both that copyright notice and the limited warranty and
;;;    restricted rights notice below appear in all supporting
;;;    documentation.
;;;
;;;    THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
;;;    WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
;;;    PURPOSE AND OF MERCHANTIBILITY ARE HEREBY DISCLAIMED BY THE
;;;    PROGRAMMER.
;;;
;;; -----------------------------------------------------------------------
(defun c:STUDWALL (/)(STUD_WALL "CMD" nil nil nil))

(defun STUD_WALL (RunType StudSize StudSpace DryWall / *error* OldClayer OldCmdEcho OldLunits OldLuPrec ActiveDoc Space StudSize StartPoint EndPoint StudSpace WallLength WallAngle Angle-180 Angle+90 Width Length NoStuds )
 
 ;;; Begin Error Handler -------------------------------------------------
(defun *error* (MSG)

	(if (not (member MSG '("Function cancelled" "quit / exit abort")))
		(princ (strcat "\n*** Program Error: " (strcase MSG) " ***"))
		(princ "\n... Program Cancelled ...")
	)
	(while (< 0 (getvar "cmdactive"))
		(command)
	)
	;; Reset environment varialbes
	(STUDWALL_RESET_ENV)
)
;;; End Error Handler ---------------------------------------------------
(STUDWALL_SET_ENV)
)
;;; ------------ SET ENVIROMENT BEFORE LAUNCH
(defun STUDWALL_SET_ENV(/)

(setq OldClayer (getvar "CLAYER"))
(setq OldCmdEcho (getvar "CMDECHO"))

(setvar "CMDECHO" 0)
(command "_undo" "BE")

(setq	ActiveDoc	(vla-get-activedocument (vlax-get-acad-object)))
(setq Space
	(if (= (getvar "cvport") 1)
		(vla-get-paperspace ActiveDoc)
		(vla-get-modelspace ActiveDoc)
	)
)
;; Create framing layer
(STUD_CREATE_LAYER "A-FRAM-WALL" "Framing Plan - Wall framing linework" "Continuous" "25" "157" "0")
(setvar "CLAYER" "A-FRAM-WALL")

;; Create wall
(if (= RunType "CMD")
	(RUN_STUDWALL)
	(GET_STUD_POINTS StudSize StudSpace DryWall)
)
)
;;; ------------ RUN STUDWALL
(defun RUN_STUDWALL (/)

;; Get wall thickness
(initget 1 "4 6 8")
(setq StudSize (getkword " \nEnter wall Thickness: (4=2x4/6=2x6/8=2x8)"))

;; Get stud spacing
(while (< (setq StudSpace (getreal " \nEnter stud spacing: "))6.0)
	(alert " Stud spacing Needs to be greater than 6\" ")
)			

;; Get drywall
(initget 1 "Yes y Y No n N")
(setq DryWall (strcase (getkword " \nAdd drywall?: (Yes/No)")))

(GET_STUD_POINTS StudSize StudSpace DryWall)
)
(defun GET_STUD_POINTS (StudSize StudSpace DryWall /)

;; Create stud block
(CREATE_STUD StudSize)

;; Define start and end points
(setq StartPoint (getpoint " \nDefine Start point for studwall: "))
(setq EndPoint (getpoint StartPoint " \nDefine end point for studwall: "))	

;; Set wall variables
(setq WallLength (distance StartPoint EndPoint))
(setq WallAngle (angle StartPoint EndPoint))	
(setq Angle-180 (- WallAngle (DTR 180)))
(setq Angle+90 (+ WallAngle (DTR 90)))

;; Justify start and end points
(setq StartPoint (polar StartPoint Angle+90 (/ Width 2)))
(setq EndPoint (polar EndPoint Angle+90 (/ Width 2)))

;; Create the wall
(CREATE_STUDWALL)
)
;;; ------------ CREATE STUDWALL
(defun CREATE_STUDWALL ( / Point Temp DWallLine1 DWallLine2 WallLine1 WallLine2 WallCenter WallEnd1 WallEnd2)

;; Create first stud
(INSERT_STUD BlockName (polar StartPoint WallAngle (/ Length 2)) WallAngle)

;; Count the number of studs
(setq NoStuds 1)

;; Create intermediate studs
(setq Point StartPoint)
(setq Temp (- WallLength 3))
(while (> Temp StudSpace)
	(setq Point (polar Point WallAngle StudSpace))
	(INSERT_STUD BlockName Point WallAngle)
	(setq Temp (- Temp StudSpace))
	
	;; Add to the stud count
	(setq NoStuds (1+ NoStuds))
)

;; Create last stud
(INSERT_STUD BlockName (polar EndPoint Angle-180 (/ Length 2)) WallAngle)

;; Add to the stud count
(setq NoStuds (1+ NoStuds))

;; Create wall lines
(setq WallCenter (vlax-invoke Space 'addline StartPoint EndPoint))
(setq WallLine1 (car (vlax-invoke WallCenter 'offset (/ Width 2))))
(setq WallLine2 (car (vlax-invoke WallCenter 'offset (-(/ Width 2)Width))))

;; Delete centerline
(vlax-invoke WallCenter 'delete)

;; Add drywall
(if (= DryWall "YES")
	(progn
		(setq DWallLine1 (car (vlax-invoke WallLine1 'offset 0.5)))
		(setq DWallLine2 (car (vlax-invoke WallLine2 'offset -0.5)))
		(setq WallEnd1 (vlax-invoke Space 'addline (vlax-get DWallLine1 'Startpoint)(vlax-get DWallLine2 'Startpoint)))
		(setq WallEnd2 (vlax-invoke Space 'addline (vlax-get DWallLine1 'Endpoint)(vlax-get DWallLine2 'Endpoint)))
	)
	(progn
		(setq WallEnd1 (vlax-invoke Space 'addline (vlax-get WallLine1 'Startpoint)(vlax-get WallLine2 'Startpoint)))
		(setq WallEnd2 (vlax-invoke Space 'addline (vlax-get WallLine1 'Endpoint)(vlax-get WallLine2 'Endpoint)))
	)
)

;; Send stud count
(princ (strcat "\nThere are " (rtos NoStuds 5 0)" studs in the wall."))

;; Reset environment varialbes
(STUDWALL_RESET_ENV)
)
;;; ------------ LAYER CREATION ROUINE
(defun STUD_CREATE_LAYER (Layer Descpition Linetype Thickness Color Plot / TmpList VLA-Obj)

;; Check to see if linetype exsists
(if (= (tblsearch "ltype" Linetype) nil)		
	(if (STUD_CHECK_LINETYPE (findfile "acad.lin") Linetype)
		(command "linetype" "load" Linetype "acad.lin" "")
		(setq Linetype "Continuous")
	)
)
;;; ------------ CREATE A LIST FOR ENTMAKE
(setq TmpList
	'((0 . "LAYER")
	(100 . "AcDbSymbolTableRecord")
	(100 . "AcDbLayerTableRecord")
	(70 . 0)
	)
	)
	;; Create layer name list
	(setq TmpList (append TmpList (list (cons 2 Layer))))
	;; Create layer color list
	(setq TmpList (append TmpList (list (cons 62 (atoi Color)))))
	;; Create layer linetype list
	(setq TmpList (append TmpList (list (cons 6 Linetype))))
	;; Create layer lineweight list
	(setq TmpList (append TmpList (list (cons 370 (atoi Thickness)))))
	;; Create layer plot list
	(setq TmpList (append TmpList (list (cons 290 (atoi Plot)))))
	;; Create layer from first item in the list
	(entmake TmpList)      
	;; Create layer description
	(if(or(= 16.1 (atof(getvar "acadver")))(< 16.1 (atof(getvar "acadver"))))
	(progn
	(setq VLA-Obj(vla-Add (vla-Get-Layers ActiveDoc)Layer))
	(vla-Put-Description VLA-Obj Descpition)
	(vlax-release-object VLA-Obj)
	)
)
)
;;; ------------ CHECKS TO SEE IF A LINETYPE IS AVAILIBLE
(defun STUD_CHECK_LINETYPE (LINFile Linetype / OpenFile LineNumber CurrentLine Result)

(setq OpenFile (open LINFile "r"))
(while (setq CurrentLine (read-line OpenFile))
	(if (wcmatch CurrentLine "`**")
		(progn				
			(setq LinetypeName (substr(car(TGS:Stringtolist CurrentLine ","))2))
			(if (= (strcase Linetype) LinetypeName)
				(setq Result T)
			)
		)
	)
)
(close OpenFile)
Result
)
;;; ------------ STRING TO LIST SUB ROUTINE
(defun TGS:StringToList (Stg Del / CurChr PosCnt TmpLst TmpStr)

(setq PosCnt 1
			TmpStr ""
)
(repeat (1+ (strlen Stg))
	(setq CurChr (substr Stg PosCnt 1))
	(if (= CurChr Del)
		(progn
			(setq TmpLst (cons TmpStr TmpLst))
			(setq TmpStr "")
		)
		(setq TmpStr (strcat TmpStr CurChr))
	)
	(setq PosCnt (1+ PosCnt))
)
(setq TmpLst (reverse TmpLst))
)
;;; ------------ INSERT STUD BLOCK SUB
(defun INSERT_STUD (BlockName InsPoint RotAngle /)

(entmake 
	(list 
		(cons 0 "INSERT") ;***
		(cons 2 BlockName) ;***
		(cons 6 "BYLAYER")
		;(cons 8 "0") ;Layer name
		(cons 10 InsPoint) ;***
		(cons 39 0.0)
		(cons 41 1.0)
		(cons 42 1.0)
		(cons 43 1.0)
		(cons 44 0.0)
		(cons 45 0.0)
		(cons 50 RotAngle)
		(cons 62 256)
		(cons 70 0)
		(cons 71 0)
		(cons 210 (list 0.0 0.0 1.0))
	)
)
)							 
;;; ------------ CREATE STUD BLOCK SUB - DOES NOT INSERT BLOCK
(defun CREATE_STUD (StudSize /)

(setq OldLunits (getvar "LUNITS"))
(setq OldLuPrec (getvar "LUPREC"))
(setvar "LUNITS" 2)
(setvar "LUPREC" 1)
(cond
	((= StudSize "4")(setq BlockName "2x4")(setq Length 1.5)(setq Width 3.5))
	((= StudSize "6")(setq BlockName "2x6")(setq Length 1.5)(setq Width 5.5))
	((= StudSize "8")(setq BlockName "2x8")(setq Length 1.5)(setq Width 7.5))
)

(if (= (tblsearch "block" BlockName) nil) 
	(progn 
		(entmake
			(list
				(cons 0 "BLOCK")
				(cons 2 BlockName)
				(cons 70 64)
				(cons 10 (list 0.0 0.0 0.0))
				(cons 8 "0")
			)
		)
		;; Left Side Line
		(entmake
			(list
				(cons 0 "LINE")
				(cons 10 (list (- (/ Length 2) Length) (- (/ Width 2) Width) 0.0))
				(cons 11 (list (- (/ Length 2) Length) (/ Width 2) 0.0))
				(cons 8 "0")
				(cons 62 256)
			)
		)
		;; Bottom Line
		(entmake
			(list
				(cons 0 "LINE")
				(cons 10 (list (- (/ Length 2) Length) (- (/ Width 2) Width) 0.0))
				(cons 11 (list (/ Length 2) (- (/ Width 2) Width)  0.0))
				(cons 8 "0")
				(cons 62 256)
			)
		)
		;; Right Side Line
		(entmake
			(list
				(cons 0 "LINE")
				(cons 10 (list (/ Length 2) (- (/ Width 2) Width)  0.0))
				(cons 11 (list (/ Length 2) (/ Width 2)  0.0))
				(cons 8 "0")
				(cons 62 256)
			)
		)
		;; Top Line
		(entmake
			(list
				(cons 0 "LINE")
				(cons 10 (list (/ Length 2) (/ Width 2)  0.0))
				(cons 11 (list (- (/ Length 2) Length) (/ Width 2) 0.0))
				(cons 8 "0")
				(cons 62 256)
			)
		)
		;; Left Cross
		(entmake
			(list
				(cons 0 "LINE")
				(cons 10 (list (- (/ Length 2) Length) (/ Width 2) 0.0))
				(cons 11 (list (/ Length 2) (- (/ Width 2) Width)  0.0))
				(cons 8 "0")
				(cons 62 
			)
		)
		;; Right Cross
		(entmake
			(list
				(cons 0 "LINE")
				(cons 10 (list (- (/ Length 2) Length) (- (/ Width 2) Width) 0.0))
				(cons 11 (list (/ Length 2) (/ Width 2)  0.0))
				(cons 8 "0")
				(cons 62 
			)
		)
		;; Endblock
		(entmake
			'((0 . "ENDBLK"))
		) 
	)
	(princ "\n\n Block found in drawing")
)
(setvar "LUNITS" OldLunits)
(setvar "LUPREC" OldLuPrec)
BlockName
)
;; ------------ DEGREES / RADIANS SUB ROUTINES
(defun DTR (NumberOfDegrees) 
(* pi (/ NumberOfDegrees 180.0))
)
;;; ------------ RESET SYSEM VARIABLES
(defun STUDWALL_RESET_ENV (/)

(command "_undo" "End")
(setvar "CMDECHO" OldCmdEcho)
(setvar "CLAYER" OldClayer)
(princ)	
)
;;;
;;; Echos to the command line
(princ "\n CreateStudWall v1.0 ©Timothy Spangler, \n  December, 2006....loaded.")
(terpri)
(princ "Type \"STUDWALL\" to begin")
(print)
;;; End echo

 

hi tim

 

it was showing like (4=2x4/6=).i could not understand ur lisp code. it could not do with meter or mm and inches.

 

could you help me.

 

best regards

hussain

Link to comment
Share on other sites

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