Jump to content

Recommended Posts

Posted

Hi,

 

I would like to add the doors through Lisp.

 

I would like to add automatically something like the picture attached (yellow doors block).

 

Thanks in advance

 

Santodoor.JPG

Posted (edited)

Is the block going to be inserted on any particular layer? If so, does the layer exist or does it have to be created? How many different door blocks do you have? Will the block have to be scaled? Where are the blocks located?

 

Have you given any thought to creating a tool palette and populating it with your most commonly used blocks? Then you can drag and drop the blocks rather than inserting via a lisp program.

Edited by ReMark
Posted

I have just one door block and i scale/orientate it each time. The layer is on the dwg block

 

It is a consistent time consuming.

 

I would like to have something like:

 

1st click: at the beginning of the door

2nd click: end of the doors

3rd click: orientation

 

the block is attached on this post

[ATTACH]59979[/ATTACH]

Posted

One block? Put it on a tool palette. Easiest and quickest solution.

Posted

Yes, I have it on the tool palette. The ploblem is I have to scale and orientate it each time

Posted

Are you're drawings done to full size or are they drawn "to scale" as one might do on a drafting board?

 

BTW...your attachment above is invalid (i.e. - no good).

Posted

Full scale. bit the door opening/orientation are different and i need to adapt the block each time.

 

door.dwg

Posted (edited)

Daily practice:

[color=#8b4513]; Block on Line, Grrr[/color]
[b][color=BLACK]([/color][/b]defun C:test [color=#8b4513];| credits to: Lee Mac |; [b][color=FUCHSIA]([/color][/b] / b bn p e [b][color=FUCHSIA])[/color][/b][/color]
[b][color=FUCHSIA]([/color][/b]setvar 'errno 0[b][color=FUCHSIA])[/color][/b]
[b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]/= 52 [b][color=MAROON]([/color][/b]getvar 'errno[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
	[b][color=NAVY]([/color][/b]setq b [b][color=MAROON]([/color][/b]car [b][color=GREEN]([/color][/b]entsel [color=#2f4f4f]"\nSelect block to reinsert <exit>: "[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
	[b][color=NAVY]([/color][/b]cond
		[b][color=MAROON]([/color][/b] [b][color=GREEN]([/color][/b]= 7 [b][color=BLUE]([/color][/b]getvar 'errno[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
			[b][color=GREEN]([/color][/b]princ [color=#2f4f4f]"\nMissed, try again."[/color][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setvar 'errno 0[b][color=GREEN])[/color][/b] 
		[b][color=MAROON])[/color][/b]
		[b][color=MAROON]([/color][/b] [b][color=GREEN]([/color][/b]and [b][color=BLUE]([/color][/b]= 'ENAME [b][color=RED]([/color][/b]type b[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]/= [b][color=RED]([/color][/b]cdr [b][color=PURPLE]([/color][/b]assoc 0 [b][color=TEAL]([/color][/b]entget b[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] [color=#2f4f4f]"INSERT"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
			[b][color=GREEN]([/color][/b]princ [color=#2f4f4f]"\nThis is not a block."[/color][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setq b nil[b][color=GREEN])[/color][/b]
		[b][color=MAROON])[/color][/b]
		[b][color=MAROON]([/color][/b]b 
			[b][color=GREEN]([/color][/b]setq bn [b][color=BLUE]([/color][/b]vla-get-EffectiveName [b][color=RED]([/color][/b]vlax-ename->vla-object b[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
			[b][color=GREEN]([/color][/b]while [b][color=BLUE]([/color][/b]/= 52 [b][color=RED]([/color][/b]getvar 'errno[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
				[b][color=BLUE]([/color][/b]and
					[b][color=RED]([/color][/b]setq p [b][color=PURPLE]([/color][/b]getpoint [color=#2f4f4f]"\nSelect a line to insert on it: <exit>"[/color][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
					[b][color=RED]([/color][/b]setq e [b][color=PURPLE]([/color][/b]car [b][color=TEAL]([/color][/b]nentselp p[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
				[b][color=BLUE])[/color][/b]
				[b][color=BLUE]([/color][/b]cond 
					[b][color=RED]([/color][/b][b][color=PURPLE]([/color][/b]not p[b][color=PURPLE])[/color][/b]
						[b][color=PURPLE]([/color][/b]setvar 'errno 52[b][color=PURPLE])[/color][/b]
					[b][color=RED])[/color][/b]
					[b][color=RED]([/color][/b][b][color=PURPLE]([/color][/b]not e[b][color=PURPLE])[/color][/b]
						[b][color=PURPLE]([/color][/b]princ [color=#2f4f4f]"\nMissed, try again."[/color][b][color=PURPLE])[/color][/b]
					[b][color=RED])[/color][/b]
					[b][color=RED]([/color][/b] 
						[b][color=PURPLE]([/color][/b]and p 
							[b][color=TEAL]([/color][/b]vl-catch-all-error-p 
								[b][color=OLIVE]([/color][/b]vl-catch-all-apply 'vlax-curve-getFirstDeriv 
								[b][color=GRAY]([/color][/b]list e [b][color=AQUA]([/color][/b]vl-catch-all-apply 'vlax-curve-getParamAtPoint [b][color=LIME]([/color][/b]list e p[b][color=LIME])[/color][/b][b][color=AQUA])[/color][/b][b][color=GRAY])[/color][/b][b][color=OLIVE])[/color][/b]
							[b][color=TEAL])[/color][/b]
						[b][color=PURPLE])[/color][/b]
						[b][color=PURPLE]([/color][/b]princ [color=#2f4f4f]"\nThis object is not a curve."[/color][b][color=PURPLE])[/color][/b]
					[b][color=RED])[/color][/b]
					[b][color=RED]([/color][/b]T
						[b][color=PURPLE]([/color][/b]and bn p e 
							[b][color=TEAL]([/color][/b]vla-InsertBlock
								[b][color=OLIVE]([/color][/b]vlax-get-property 
									[b][color=GRAY]([/color][/b]vla-get-ActiveDocument [b][color=AQUA]([/color][/b]vlax-get-acad-object[b][color=AQUA])[/color][/b][b][color=GRAY])[/color][/b] 
									[b][color=GRAY]([/color][/b]if [b][color=AQUA]([/color][/b]= 1 [b][color=LIME]([/color][/b]getvar 'CVPORT[b][color=LIME])[/color][/b][b][color=AQUA])[/color][/b] 'Paperspace 'Modelspace[b][color=GRAY])[/color][/b]
								[b][color=OLIVE])[/color][/b] [color=#8b4513]; AcSpc[/color]
								[b][color=OLIVE]([/color][/b]vlax-3D-point p[b][color=OLIVE])[/color][/b] 
								bn
								1.
								1.
								1.
								[b][color=OLIVE]([/color][/b]alg-ang e p[b][color=OLIVE])[/color][/b]
							[b][color=TEAL])[/color][/b]
							[b][color=TEAL]([/color][/b]setvar 'errno 52[b][color=TEAL])[/color][/b]
						[b][color=PURPLE])[/color][/b]
					[b][color=RED])[/color][/b]
					[b][color=BLUE])[/color][/b]
				[b][color=GREEN])[/color][/b]
				[b][color=MAROON])[/color][/b]
			[b][color=MAROON]([/color][/b]T nil[b][color=MAROON])[/color][/b]
	[b][color=NAVY])[/color][/b][color=#8b4513]; cond[/color]
[b][color=FUCHSIA])[/color][/b][color=#8b4513]; while[/color]
[b][color=FUCHSIA]([/color][/b]princ[b][color=FUCHSIA])[/color][/b]
[b][color=BLACK])[/color][/b][color=#8b4513];| defun |; [b][color=BLACK]([/color][/b]vl-load-com[b][color=BLACK])[/color][/b] [b][color=BLACK]([/color][/b]princ[b][color=BLACK])[/color][/b][/color]

[color=#8b4513]; BIGAL's example of [color=#2f4f4f]"vlax-curve-getFirstDeriv"[/color] usage:[/color]
[b][color=BLACK]([/color][/b]defun alg-ang [b][color=FUCHSIA]([/color][/b]obj pnt[b][color=FUCHSIA])[/color][/b]
[b][color=FUCHSIA]([/color][/b]angle '[b][color=NAVY]([/color][/b]0. 0. 0.[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]vlax-curve-getFirstDeriv obj [b][color=MAROON]([/color][/b]vlax-curve-getParamAtPoint obj pnt[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b]
[b][color=BLACK])[/color][/b][color=#8b4513]; defun[/color]

3o6ZsTNdaWhu8Y4PYc.gif

Edited by Grrr
Posted

This lisp is just for orientations, not for scale. Is not helpful in my case.

 

Attached I add a new version of the block whit parameter

 

Rotate - Scale - Flip

 

 

door_smart.dwg

Posted

Are you aware of the align command?

It just expects 4 points, enter and Yes or No for scale.

Posted

I used align .... If the door are few it is ok... When i Need to add 60 different door it is a time consuming . I made a dinamic bock but is still a slow method

Posted
I used align .... If the door are few it is ok... When i Need to add 60 different door it is a time consuming . I made a dinamic bock but is still a slow method

This might help:

(defun C:test ;| credits to: Lee Mac |; ( / *error* cm SelBname bn p Blk ll ur msg SS cen Grrr mc )

(defun *error* (m) (redraw)(and cm (setvar 'cmdecho cm)) (and m (print m)) (princ))
(defun SelBname ( / e bn )
	(setvar 'errno 0)
	(while (/= 52 (getvar 'errno))
		(setq e (car (entsel "\nSelect block to reinsert <exit>: ")))
		(cond
			( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") (setvar 'errno 0) )
			( (and (= 'ENAME (type e)) (/= (cdr (assoc 0 (entget e))) "INSERT")) 
				(princ "\nThis is not a block.") (setq e nil)
			)
			( (and e (not (alert "Visit lee-mac.com")) (setq bn (vla-get-EffectiveName (vlax-ename->vla-object e))) (setvar 'errno 52)) )
		); cond
	); while
	bn
); defun SelBname

(redraw) (setq bn (SelBname))
(while
	(and
		(setq cm (getvar 'cmdecho)) (setvar 'cmdecho 0)
		bn
		(last (setq p (list (getpoint "\nSpecify insertion point <exit>: "))))
		(last (setq p (append p (list (getpoint (last p) "\nSpecify second point <exit>: ")))))
		(not (apply 'grdraw (append p (list 1 7))))
		(setq Blk
			(vla-InsertBlock
				(vlax-get-property 
					(vla-get-ActiveDocument (vlax-get-acad-object)) 
					(if (= 1 (getvar 'CVPORT)) 'Paperspace 'Modelspace)
				) ; AcSpc
				(vlax-3D-point (car p)) bn 1. 1. 1. 0. 
			)	
		)
	)
	(progn
		(vla-GetBoundingBox Blk 'll 'ur)
		(vla-ScaleEntity Blk (vlax-3D-point (car p))
			(/ (apply 'distance p) (abs (apply '- (mapcar 'car (mapcar 'vlax-safearray->list (list ll ur))))) ) 
		)
		(vla-put-Rotation Blk (apply 'angle p))
		(setq msg "\nPress [TAB] to change orientation, [ENTER] to exit: ")
		(and msg (princ msg)) (setvar 'errno 0)
		(setq SS (ssadd))
		(ssadd (handent (vla-get-Handle Blk)) SS)
		(setq cen (apply 'mapcar (cons '(lambda (a b) (/ (+ a b) 2.)) p)))
		(while (/= 52 (getvar 'errno))
			(setq Grrr (grread T))
			(cond
				((= (car Grrr) 2)
					(cond
						((= (cadr Grrr) (ascii "\t"))
							(and msg (princ msg))
							(and (not mc) (setq mc 0))
							(setq mc (rem (+ mc 1) 4))
							(cond
								( (or (= mc 1) (= mc 3) )
									(command "_.MIRROR" SS "" "_non" cen "_non" (polar cen (+ (apply 'angle p) (/ PI 2.)) (apply 'distance p)) "_Y")
								)
								( (or (= mc 2) (= mc 0) )
									(command "_.MIRROR" SS "" "_non" cen "_non" (polar cen (apply 'angle p) (apply 'distance p)) "_Y")
								)
							)
						)
						((= (cadr Grrr) (ascii "\r"))
							(princ "\nExiting.") (redraw) (setvar 'errno 52)
						)
					); cond
				)
				((= (car Grrr) 25)
					(princ "\nExiting.") (redraw) (setvar 'errno 52)
				)
			); cond
		); while
	); progn
); while/if
(and cm (setvar 'cmdecho cm))
(princ)
);| defun |; (vl-load-com) (princ)

You just need to specify 2 points, hit Tab key and Enter when done.

Posted

If you have a look at this image its done by slicing out a section of the wall and then inserting the door details all in 2D+. The width is just input. Its asks for a start point and a direction swing in or out draws the door jamb. Now its copy righted so no code but the total package still exists if you want more info send me a PM.

 

If I was to redo this task I would use a dynamic block door so much easier to resize.

house2.jpg

Posted
This might help:

(defun C:test ;| credits to: Lee Mac |; ( / *error* cm SelBname bn p Blk ll ur msg SS cen Grrr mc )

(defun *error* (m) (redraw)(and cm (setvar 'cmdecho cm)) (and m (print m)) (princ))
(defun SelBname ( / e bn )
	(setvar 'errno 0)
	(while (/= 52 (getvar 'errno))
		(setq e (car (entsel "\nSelect block to reinsert <exit>: ")))
		(cond
			( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") (setvar 'errno 0) )
			( (and (= 'ENAME (type e)) (/= (cdr (assoc 0 (entget e))) "INSERT")) 
				(princ "\nThis is not a block.") (setq e nil)
			)
			( (and e (not (alert "Visit lee-mac.com")) (setq bn (vla-get-EffectiveName (vlax-ename->vla-object e))) (setvar 'errno 52)) )
		); cond
	); while
	bn
); defun SelBname

(redraw) (setq bn (SelBname))
(while
	(and
		(setq cm (getvar 'cmdecho)) (setvar 'cmdecho 0)
		bn
		(last (setq p (list (getpoint "\nSpecify insertion point <exit>: "))))
		(last (setq p (append p (list (getpoint (last p) "\nSpecify second point <exit>: ")))))
		(not (apply 'grdraw (append p (list 1 7))))
		(setq Blk
			(vla-InsertBlock
				(vlax-get-property 
					(vla-get-ActiveDocument (vlax-get-acad-object)) 
					(if (= 1 (getvar 'CVPORT)) 'Paperspace 'Modelspace)
				) ; AcSpc
				(vlax-3D-point (car p)) bn 1. 1. 1. 0. 
			)	
		)
	)
	(progn
		(vla-GetBoundingBox Blk 'll 'ur)
		(vla-ScaleEntity Blk (vlax-3D-point (car p))
			(/ (apply 'distance p) (abs (apply '- (mapcar 'car (mapcar 'vlax-safearray->list (list ll ur))))) ) 
		)
		(vla-put-Rotation Blk (apply 'angle p))
		(setq msg "\nPress [TAB] to change orientation, [ENTER] to exit: ")
		(and msg (princ msg)) (setvar 'errno 0)
		(setq SS (ssadd))
		(ssadd (handent (vla-get-Handle Blk)) SS)
		(setq cen (apply 'mapcar (cons '(lambda (a b) (/ (+ a b) 2.)) p)))
		(while (/= 52 (getvar 'errno))
			(setq Grrr (grread T))
			(cond
				((= (car Grrr) 2)
					(cond
						((= (cadr Grrr) (ascii "\t"))
							(and msg (princ msg))
							(and (not mc) (setq mc 0))
							(setq mc (rem (+ mc 1) 4))
							(cond
								( (or (= mc 1) (= mc 3) )
									(command "_.MIRROR" SS "" "_non" cen "_non" (polar cen (+ (apply 'angle p) (/ PI 2.)) (apply 'distance p)) "_Y")
								)
								( (or (= mc 2) (= mc 0) )
									(command "_.MIRROR" SS "" "_non" cen "_non" (polar cen (apply 'angle p) (apply 'distance p)) "_Y")
								)
							)
						)
						((= (cadr Grrr) (ascii "\r"))
							(princ "\nExiting.") (redraw) (setvar 'errno 52)
						)
					); cond
				)
				((= (car Grrr) 25)
					(princ "\nExiting.") (redraw) (setvar 'errno 52)
				)
			); cond
		); while
	); progn
); while/if
(and cm (setvar 'cmdecho cm))
(princ)
);| defun |; (vl-load-com) (princ)

You just need to specify 2 points, hit Tab key and Enter when done.

 

I received this error

 

bad argument type: numberp: #

Posted
I received this error

 

bad argument type: numberp: #

 

Thats weird, everything works fine on my end.

BlkFunTest.gif

You could provide some assitance by following this tutorial to figure out where did the code fail.

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