blampman Posted February 21, 2010 Posted February 21, 2010 This is my first real attempt at writing an AutoCAD lisp and I was looking for help. The lisp I have written does essentially what I would like it to do but I would like it to work better. When I layout construction drawings from my 3D models I go through a process to create 2D drawing repeatedly. The process involves making a profile using “solprof”, then exploding the blocks created, moving objects lines to appropriate layers, purging the layers created by the solprof command, and pasting the profile where I want it in model space. The lisp I have written works but it repeatedly asks for user input and I would like to minimize the need for clicks of the mouse. If I could make this lisp so all that it asks for is the objects to make a profile of and a point in model space to paste the profile that would be great. With what I have outlined in my lisp it doesn’t seem impossible. Like I said this is my first attempt and any suggestions on how to clean this lisp would be appreciated. ;The purpose of this lisp is to creat a Solid Profile of solid objects with the resulting profile on my standard layers for visable and hidden. (defun C:SOLPRO () (command "-layer" "make" "HIDDEN" "" ) (command "-layer" "make" "SOLPROF - VIS" "" ) (command "undo" "mark") ;set point to undo to, this will get rid of the layers create by the "solprof" command (setq selobj (ssget)) ;select 3D solids to create profile of objects desired by user (command "SOLPROF" selobj "" "Y" "Y" "Y") (command "_layiso" "LAST" "" );isolates the hidden lines created by the "solprof" command without user input (prompt "select objects to explode:") (command "explode" pause "") ;user selects the block of hidden lines created by the "solprof" command to be able to exploded it. I would like to get rid of the need for user input on this step. When I change the pause to "ALL" the lisp does not compleat (command "change" "all" "" "p" "LA" "HIDDEN" "");moves hidded lines on layer created by solprof command to a regular named layer (command "_layuniso") ; un-isolates the hidden lines so we can work on the visable lines (prompt "Select visable line:") (setq selvis (ssget)) ; user selects visable line, I would like to eliminate the need for user input here if possible (command "_layiso" selvis "" );isolates the visable lines created by the "solprof" command without user input (command "explode" selvis "") (command "change" "all" "" "p" "LA" "SOLPROF - VIS" "");moves visable lines on layer created by solprof command to a layer used by my company (command "'_.VPLAYER" "Thaw" "HIDDEN" "current" ""); make the HIDDEN layer visable so we can select it (command "'_.VPLAYER" "Thaw" "SOLPROF - VIS" "current" ""); make the SOLPROF-VIS layer visable so we can select it (command "_UCS" "V") ;changes UCS so we can cut and paste the solid profile (prompt "Select objects to keep and move:") (setq selprof (ssget)) ;user selects lines that need to be cut and paste, I would like to get rid of the need for user input on this step if possible, would like it if the lisp could automatically select the new created lines (command "cutclip" selprof "");cut (command "undo" "b"); undo everything we have done, this step erases the layers created by the "solprof" command (command "model") ;switch to modelspace so we can past the solid profile where we want it to be able to make construction drawings (command "-view" "_front") (command "_UCS" "V") ;changes UCS so we can cut and paste the solid profile (command "pasteclip");paste the clip (prompt "End Program") (princ) ); end defun Thank You Lampman Quote
The Buzzard Posted February 21, 2010 Posted February 21, 2010 This is my first real attempt at writing an AutoCAD lisp and I was looking for help. The lisp I have written does essentially what I would like it to do but I would like it to work better. When I layout construction drawings from my 3D models I go through a process to create 2D drawing repeatedly. The process involves making a profile using “solprof”, then exploding the blocks created, moving objects lines to appropriate layers, purging the layers created by the solprof command, and pasting the profile where I want it in model space. The lisp I have written works but it repeatedly asks for user input and I would like to minimize the need for clicks of the mouse. If I could make this lisp so all that it asks for is the objects to make a profile of and a point in model space to paste the profile that would be great. With what I have outlined in my lisp it doesn’t seem impossible. Like I said this is my first attempt and any suggestions on how to clean this lisp would be appreciated. ;The purpose of this lisp is to creat a Solid Profile of solid objects with the resulting profile on my standard layers for visable and hidden. (defun C:SOLPRO () (command "-layer" "make" "HIDDEN" "" ) (command "-layer" "make" "SOLPROF - VIS" "" ) (command "undo" "mark") ;set point to undo to, this will get rid of the layers create by the "solprof" command (setq selobj (ssget)) ;select 3D solids to create profile of objects desired by user (command "SOLPROF" selobj "" "Y" "Y" "Y") (command "_layiso" "LAST" "" );isolates the hidden lines created by the "solprof" command without user input (prompt "select objects to explode:") (command "explode" pause "") ;user selects the block of hidden lines created by the "solprof" command to be able to exploded it. I would like to get rid of the need for user input on this step. When I change the pause to "ALL" the lisp does not compleat (command "change" "all" "" "p" "LA" "HIDDEN" "");moves hidded lines on layer created by solprof command to a regular named layer (command "_layuniso") ; un-isolates the hidden lines so we can work on the visable lines (prompt "Select visable line:") (setq selvis (ssget)) ; user selects visable line, I would like to eliminate the need for user input here if possible (command "_layiso" selvis "" );isolates the visable lines created by the "solprof" command without user input (command "explode" selvis "") (command "change" "all" "" "p" "LA" "SOLPROF - VIS" "");moves visable lines on layer created by solprof command to a layer used by my company (command "'_.VPLAYER" "Thaw" "HIDDEN" "current" ""); make the HIDDEN layer visable so we can select it (command "'_.VPLAYER" "Thaw" "SOLPROF - VIS" "current" ""); make the SOLPROF-VIS layer visable so we can select it (command "_UCS" "V") ;changes UCS so we can cut and paste the solid profile (prompt "Select objects to keep and move:") (setq selprof (ssget)) ;user selects lines that need to be cut and paste, I would like to get rid of the need for user input on this step if possible, would like it if the lisp could automatically select the new created lines (command "cutclip" selprof "");cut (command "undo" "b"); undo everything we have done, this step erases the layers created by the "solprof" command (command "model") ;switch to modelspace so we can past the solid profile where we want it to be able to make construction drawings (command "-view" "_front") (command "_UCS" "V") ;changes UCS so we can cut and paste the solid profile (command "pasteclip");paste the clip (prompt "End Program") (princ) ); end defun Thank You Lampman Lampman, Trust me when I tell you I am impressed by your honest attempt at lisp, But you really need to break away from the repetitious command call style. While I have used command calls in the past, They were kept to a limited few. You really need to take a different approach to programming. I am sorry if I cannot give you the answer that you are looking for, But I am sure others here will tell you the same or point you in another direction. Although I am not versed in it at all, I would suggest a Visual Lisp approach or entity make. Maybe someone else can be more helpful here. Nice attempt anyway. The Buzzard Quote
shirazbj Posted February 22, 2010 Posted February 22, 2010 I am also interested in command. I was wondering what a scr file could do in LT. I need a scr to make some decent drawings. Also I don't like too much user input. Is it possible? Quote
The Buzzard Posted February 22, 2010 Posted February 22, 2010 On this link you will find some entmakex functions by Lee Mac that may be useful to you. http://www.cadtutor.net/forum/showthread.php?t=44768 Also see this link as well, A great learning source. http://www.afralisp.net/ Quote
shirazbj Posted February 23, 2010 Posted February 23, 2010 That was an intertesing topic - entmake. But for LT, there is no Lisp. I can only use the command. I want write the command into a script file. When run it, I want the least input from user. Quote
The Buzzard Posted February 23, 2010 Posted February 23, 2010 That was an intertesing topic - entmake. But for LT, there is no Lisp. I can only use the command. I want write the command into a script file. When run it, I want the least input from user. shirazbj, I was responding to the person who started this thread. I do not know much about scripting and it is off the subject for this thread. If you want an answer to your question, You will need to start your own thead with the question in the header area. You will get more responces that way. Quote
shirazbj Posted February 24, 2010 Posted February 24, 2010 Hi LampMan, For the "Explode all" please try "EXPLODE " & "ALL " & " " That is a blank after ALL and another balnk after that It works for me. Cean Quote
MajorWedgee Posted March 21, 2022 Posted March 21, 2022 I realize this is a very old topic, but I used the code originally posted here, and added to it, getting it to work a bit better, for me at least. So I figure the least I can do is post it up here in case someone else comes along in another 10 years and wants to use it. I tried to comment what each line does to make it easier for someone else to follow. Mine does not do the hidden lines, as it's generally not needed for my purposes, and would only add complexity to the lisp. There's a good chance it could be better, as I'm no lisp super guru, but it gets the job done. ;The purpose of this lisp is to create a Solid Profile of solid objects with the resulting profile on standard layers (no extra layers from solprof command) (defun C:2diso () (if (or (= (getvar "cvport") 1) ; Check to see if in paperspace (= (getvar "cvport") 2) ; Check to see if in modelspace ) (alert (strcat (alert "You must be in an active viewport in paperspace.") ;if true, display popup (print "You must be in an active viewport in paperspace.") ;if true, print to command prompt (exit) ;if true, exit lisp ) ) ) (command "._UNDO" "_Begin" ) ;set undo begin point, this is where an undo will go back to, making the command undo in one step instead of multiple (setvar "cmdecho" 0) ;turn printing to command prompt off, keeps command prompt history from being spammed by all the messages (setq os (getvar 'osmode)) ; save current object snap settings to variable (setvar 'osmode 0) ; turn off object snap (setq clyt (getvar 'ctab)) ; save current layout tab to variable (setq clyr (getvar 'clayer)) ; save current layer to variable (command "undo" "mark") ;set point to undo to, this will get rid of the layers create by the "solprof" command (setq selobj (ssget)) ;select 3D solids to create profile of objects desired by user (setq vpnum (getvar 'cvport)) ; save current viewport to variable so we can switch back to it later (command "SOLPROF" selobj "" "N" "Y" "Y") ; autocad command to create the 2d view (command "_layiso" "LAST" "" );isolates the block created by the "solprof" command without user input (command "explode" "all") ;selects the block of created by the "solprof" command and explodes it (command "_UCS" "V") ;changes UCS so we can cut the solid profile with coords relative to the current view (command "change" "all" "" "p" "LA" "0" "");moves lines on layer created by solprof command to 0 layer (command "_layuniso") ; unisolate layers (command "cutclip" "previous" "");cut previous selection which would be the exploded block created by solprof (command "undo" "b"); undo everything we have done, this step undo's the layers created by the "solprof" command (COMMAND "-layout" "s" "Model") ;switch to modelspace so we can past the solid profile (command "-view" "_top") ; change view to top (command "_UCS" "w") ;changes UCS so we can paste the solid profile projected true to WCS (COMMAND "-layer" "s" "0" "") ;set layer to 0 layer (command "-layer" "m" "IS-Iso" "") ;make new layer IS-Iso if it doesn't already exist (command "pasteblock" pause);paste the clip as a block (COMMAND "-layout" "s" clyt) ;change layout tab back to where we were at beginning (if (= (getvar "vpmaximizedstate") 1) ;check to see if viewport is maximized (command "vpmin") ;if true, minimize viewport ) (setvar 'cvport vpnum) ;set the active viewport back to where we were at beginning, needed because vpmin command leaves you in paperspace ; code to unlock current viewport begin (setq AcadObject(vlax-get-acad-object) ActiveDocumentObject(vlax-get-property AcadObject "ActiveDocument") ActiveVport(vla-get-ActivePViewport ActiveDocumentObject) VportMode(vla-get-DisplayLocked ActiveVport) ) (if (equal :vlax-true VportMode) (vla-put-DisplayLocked ActiveVport :vlax-false) ) ; code to unlock viewport end (command "-view" "_top") ; set view in viewport to top (command "zoom" "object" "last" "") ; zoom extents on last selected object in viewport (command "zoom" "s" ".95x") ; reduce zoom by 5% (command "-visualstyles" "C" "2dwireframe") ; set visual style (COMMAND "-layer" "s" clyr "") ;reset current layer to what it was before command started ; code to lock current viewport begin (setq AcadObject(vlax-get-acad-object) ActiveDocumentObject(vlax-get-property AcadObject "ActiveDocument") ActiveVport(vla-get-ActivePViewport ActiveDocumentObject) VportMode(vla-get-DisplayLocked ActiveVport) ) (if (equal :vlax-false VportMode) (vla-put-DisplayLocked ActiveVport :vlax-true) ) ; code to lock viewport end (setvar "osmode" os) ; reset object snap mode to what it was before lisp began (command-s "._UNDO" "_End") ; set mark for undo end (setvar "cmdecho" 1) ;turn printing to command prompt back on ); end defun Quote
Recommended Posts
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.