setting layers based on object selection

setting layers based on object selection

shillmanB5QQZ
Contributor Contributor
3,059 Views
37 Replies
Message 1 of 38

setting layers based on object selection

shillmanB5QQZ
Contributor
Contributor

Definite LISP newbie.  This is my first.  I know, big undertaking.  I have been working this lisp routine that you select the wall, select point on wall for the start of the break, select door width and a point on perpendicular line and it will break both lines and draw the ends of the walls in on the correct layer, and inserts the door block on the correct layer.  I have 4 possible scenarios for the wall layers, (EXST-WALL-INTR, EXST-WALL EXTER, NEW-WALL-INTR, NEW-WALL-EXTR) and 4 scenarios for the door layer (EXST-DOOR-EXTR, EXST-DOOR-INTR, NEW-DOOR-EXTR, NEW-DOOR-INTR )  I have accomplished this task . . . .  to an extent.  I have figured out setting the wall layers.  The issue is having 4 possibilities of door layers based on what wall layer is picked.   I have made 2 lisp routines, one for existing and one for new.  I would like to have one routine for all scenarios.  I am wonder if there is a way to to have one routine (Door.lisp) that can process all existing and new conditions and set appropriate layers.  I have found help from various sites on the internet to put this routine together but can seem to find an answer to what I am looking for.  Hence the reason for this post.  Here is what I have found, pieced together and figured out so far.

 

;Program to cut door opening in wall and insert door on correct layer -- DoorExst.lsp
(defun c:doorexst (/ pt1 pt2 pt3 pt4 ang1 ang2 dst1 osnap1 str1 clyr wlyr bfind msg)
(setvar "cmdecho" 0)
(command "-purge" "b" "door" "n")
(setq osnap1 (getvar "osmode"))
(setq clyr (getvar "clayer"))
(defun *error* (msg)
(setvar "osmode" osnap1)
(setvar "clayer" clyr)
(princ msg)
(princ)
)
(setvar "osmode" 512) ;nearest osnap mode
(setq wlyr (entget (car (entsel "\nSelect Wall: "))));end setq
(setq pt1 (getpoint "\nSelect point on wall to start point of opening: ")) ;get first break point
(setq pt2 (getpoint pt1 "\nEnter endpoint of opening: ")) ;get second break point
(setvar "osmode" 128) ;perpend osnap mode
(setq pt3 (getpoint pt1 "\nSelect opposite side of wall: "));get 2nd line
(Setvar "osmode" 0) ;no osnap mode
(setq ang1 (angle pt1 pt3)) ;find angle btwn lines
(setq dst1 (distance pt1 pt3)) ;find dist. btwn lines
(setq pt4 (polar pt2 ang1 dst1)) ;derive pt4 on 2nd line
(setq ang2 (* (angle pt1 pt2)57.2958)) ;find angle for door insertion
(setvar "clayer" (cdr (assoc 8 wlyr);end set current layer
(command
"break" pt1 pt2 ;break 1st line
"break" pt3 pt4 ;break 2nd line
"line" pt1 pt3 "" ;close ends of lines
"line" pt2 pt4 ""
);end command
(defun intr ()
(setvar "clayer" "exst-door-intr")
);end intr
(defun extr ()
(setvar "clayer" "exst-door-extr")
);end extr
(initget "Exterior Interior");end initget
(setq str1 (getkword "Is this an Exterior or Interior door?<Exterior/Interior>:"));end str1
(if (= str1 "Exterior")
(extr)
(intr)
);end if
(defun bfind (/ bfind)
(setq bfind (tblsearch "block" "standards"))
(if (not bfind)(command "-insert" "standards.dwg=" "0,0" "" "" ""))
(princ "Standards is already inserted. ")
(command "_.erase" "l" "")
);end bfind
(bfind)
(princ)
(command "-insert" "door" pt3 1 1 ang2)
(command "draworder" "l" "" "b")
(setvar "clayer" clyr)
(setvar "osmode" osnap1)
(setvar "cmdecho" 1)
(princ)
);end doorexst

 

 

Any help would be greatly appreciated.  Also, I know the structure is probably less than desirable.  All suggestions on lisp structure are welcome as well.  New to these forums, if this needs to be move to a more appropriate location feel free to move.

 

Thanks in advance,

Scott

 

0 Likes
3,060 Views
37 Replies
Replies (37)
Message 21 of 38

shillmanB5QQZ
Contributor
Contributor

Thanks, that fixed the "OpenAngle" issue.  So if I add the multiplier to @Z9E3zK5E code to convert from radians, it should work?

 

(setq ang2 (* (- ang1 (/ pi 2) 57.2958)))

0 Likes
Message 22 of 38

shillmanB5QQZ
Contributor
Contributor

Ok . . . . Here is what is happening now.  Horizontal works fine.  Now, Angled walls and vertical walls are looking like this.  @Kent1Cooper , you said there is a more precise way to accomplish this.  Is it more reliable and more consistent?  Also,  "OpenAngle" is not fixed.  The door comes in "open30" no matter what I select, with the exception of "closed".  That one does work.

0 Likes
Message 23 of 38

shillmanB5QQZ
Contributor
Contributor

Another question . . . .  what is going on with the *d-siz*??  I havent heard of or even seen anything being placed between two astericks.

 

Thanks

0 Likes
Message 24 of 38

Kent1Cooper
Consultant
Consultant

@shillmanB5QQZ wrote:

.....  So if I add the multiplier to @Z9E3zK5E code to convert from radians, it should work?

(setq ang2 (* (- ang1 (/ pi 2) 57.2958)))


With parentheses corrected, I expect so:

(setq ang2 (* (- ang1 (/ pi 2)) 57.2958))

Kent Cooper, AIA
0 Likes
Message 25 of 38

shillmanB5QQZ
Contributor
Contributor

Sorry,  That was a typo in my last post. 

 

(setq ang2 ((- ang1 (/ pi 2)) 57.2958)     is how I have it. The screen shot from my previous post was the result.

 

 

0 Likes
Message 26 of 38

Kent1Cooper
Consultant
Consultant
Accepted solution

@shillmanB5QQZ wrote:

.... you said there is a more precise way to accomplish this.  Is it more reliable and more consistent?  ....


It should only affect the precision as a matter of number of decimal places, though as I said the multiplier you have may be close enough for your purposes.

One way would be to skip the conversion where ang2 is set, leave it in radians, and use it as text-string input for the rotation in the Insert command:

 

(command "-insert" "door" pt3 1 (angtos ang2 0 8))

 

Another way you can find if you Search the Forum for  (rtd  [which is a commonly-used name for a little function to convert radians to degree with greater mathematical precision].

Kent Cooper, AIA
0 Likes
Message 27 of 38

Kent1Cooper
Consultant
Consultant

@shillmanB5QQZ wrote:

 . . .  what is going on with the *d-siz*??  I havent heard of or even seen anything being placed between two astericks.


That's just a convention that some people use to differentiate variable names that are global [and stick around after the routine is finished, such as to offer a default value on subsequent use] from those that are localized [and disappear when it's over].  Some use just one asterisk at the beginning, some use underscore(s) instead of asterisk(s) -- there are various approaches.  It's not necessary, but can be visually helpful when reviewing code.

Kent Cooper, AIA
0 Likes
Message 28 of 38

ВeekeeCZ
Consultant
Consultant
Accepted solution

It's easy to fix

Message 29 of 38

shillmanB5QQZ
Contributor
Contributor

Thanks @Kent1Cooper .  That fixed it!  Any thoughts on why the door block will only insert with an "OpenAngle" of 30 degrees and closed?  

0 Likes
Message 30 of 38

Kent1Cooper
Consultant
Consultant

@shillmanB5QQZ wrote:

Thanks @Kent1Cooper .  That fixed it!  Any thoughts on why the door block will only insert with an "OpenAngle" of 30 degrees and closed?  


I expect @ВeekeeCZ 's latest version should overcome that.  Earlier, the putting together of the User's choice into a visibility state name didn't have the same format as the names for those in the sample drawing [a space between "Open" and the number part, and an extra character following], but it looks like now it does.

Kent Cooper, AIA
Message 31 of 38

shillmanB5QQZ
Contributor
Contributor

@Kent1Cooper 

 

If I may request your assistance again.  I have replicated the "door.lisp" and created a "window.lisp".  All is working well with the exception, I am having a problem figuring out how to modify the the code for the block attributes.  Also, if I escape out of the command before it is finished, it won't work again until I start over again with a new drawing.  See attached sample drawing and lisp file.

 

Thanks in advance

0 Likes
Message 32 of 38

shillmanB5QQZ
Contributor
Contributor

@Kent1Cooper 

Update to previous reply . . .

I am having issues modifying the code for the dynamic properties and visibility states of the window block.  Not attributes.

Thanks!

0 Likes
Message 33 of 38

Kent1Cooper
Consultant
Consultant

@shillmanB5QQZ wrote:

@Kent1Cooper 

....
I am having issues modifying the code for the dynamic properties and visibility states of the window block.  Not attributes. ....


I am not the one to help with dynamic blocks, having almost no experience with them.  I hope someone else will step in.

Kent Cooper, AIA
Message 34 of 38

shillmanB5QQZ
Contributor
Contributor

If I may, I'd like to enlist your help once again.  Could you take a look at my post from yesterday.  I attached a sample dwg and a lsp file.  I thought it was Kent1cooper that helped with the dynamic block portion but it wasn't.  

 

Thanks in advance

0 Likes
Message 35 of 38

shillmanB5QQZ
Contributor
Contributor

@ВeekeeCZ 

 

Update . . . .  The only part of the routine that is not working is setting the "Windowwidth".   Line 52 I tried to set *w-width* to be *w-size*.  Line 77 I want to plug that value into the "SetDynPropValue" for "Windowwidth".  

0 Likes
Message 36 of 38

ВeekeeCZ
Consultant
Consultant

?? I don't understand. Why you keep on having the WindowSize if there is no such property... but you have Widnowwidht instead?

0 Likes
Message 37 of 38

ВeekeeCZ
Consultant
Consultant
Accepted solution

Heres the lisp. don't think there is some major issue. Just noted siz-wid mismatch, imho.

Added shortcut for win type - you can type just e2 or n4...

Try and see.

Good luck.

Message 38 of 38

shillmanB5QQZ
Contributor
Contributor

Thank you for catching that.  After removing some lines and making a change to set the dynamic property of "windowwidth" to be *w-siz".  It worked.  

 

Thanks again to both you and @Kent1Cooper  for all the help.

0 Likes