Jump to content

Recommended Posts

Posted

Well I believe my script (.scr) to be complete. Because you guys have been so helpful in helping me finish it I figured I would submit it on the site. I am open to any suggestions.

 

;;we start with running some processes only if this is the first
;;pass on the drawing
;;
(if (= runnum nil)
 (progn
   ;;
   ;;ensure we are in paperspace incase the drawing was last saved
   ;;in modelspace and if first run then set viewport q to 2
   ;;
   (command "tilemode" "0")
   (command "pspace")
   ;;
   ;;save a copy of original drawing for conversion process
   ;;as 2004 with "ACAD-" on front of filename
   ;;
   (vl-file-delete (strcat (getvar "DWGPREFIX") "ACAD-" (getvar "DWGNAME")))
   (command "saveas" "2004" (strcat (getvar "dwgprefix") "ACAD-"(getvar "dwgname")))
   ;;
   ;;step one is to unlock all layers so if something that is
   ;;visible was locked it is still
   ;;selectable where frozen or off layers/items will still be unselectable
   ;;
   (command "layer" "u" "*" "")
   ;;
   ;;one variable for trimming and extending is projmode when set to 1 it
   ;;will project the cutting line in al three planes so if there are 3d
   ;;lines/objects the projection of the cutting line will get them too
   ;;
   (setvar "projmode" 1)
   ;;
   ;;another variable for exploding restrics or allows selection sets
   ;;
   (setvar "qaflags" 1)
   ;;
   ;;if the layer defpoints doesn't exist then we need to create it
   ;;and ensure that the plot setting is to not plot
   ;;
   (command "layer" "m" "defpoints" "p" "n" "" "")
   ;;
   ;;if the current layer is turned off then the selection set
   ;;can't get objects drawn by the script so a new layer is made
   ;;to ensure that these objects will be selectable
   ;;
   (command "layer" "m" "deleteme123" "")
   ;;
   ;;e-transmit will not do anything with external references that
   ;;were unloaded so we remove all left over external references
   ;;
   (command "XREF" "D" "*")
   ;;
   ;;now we explode all dimensions in paperspace if any
   ;;
   (setq ss (ssget "all" '((0 . "DIMENSION")))) 
   (if (> (sslength ss) 0)
     (command "._explode" ss "")
   )
 )
)
;;
;;if the drawing has no viewports IE electrical one-line diagrams ect...
;;then we just want to convert whats in paper to model so we wrap it up
;;
(if (eq (length (vports)) 1)
 (progn
   (command "zoom" "e")
   ;;
   ;;we copy everything in paperspace which should be all of the original
   ;;viewing contents that printed on paper some titleblocks had insertion
   ;;points that weren't in the lower left hand corner of the border
   ;;so we copy clip to get a basepoint of that corner
   ;;
   (command "copyclip" "c" "-10,-10" "120,120" "")
   ;;
   ;;we want to delete any objects that were off or frozen in paper
   ;;and in model
   ;;
   (command "laythw")
   (command "layon")
   (command "zoom" "e")
   (command "erase" "all" "")
   (command "model")
   (command "zoom" "e")
   (command "erase" "all" "")
   ;;
   ;;paste the paperspace contents into model
   ;;
   (command "pasteclip" "0,0,0")
   ;;
   ;;there is no more need for layer deleteme123 so we set
   ;;the layer to 0 so the deleteme123 layer is purged out
   ;;
   (command "layer" "s" "0" "")
   (command "purge" "all" "" "n")
   (command "purge" "all" "" "n")
   (command "purge" "all" "" "n")
   (command "zoom" "e")
   ;;
   ;;final audit
   ;;
   (command "audit" "y")
   (command "tilemode" "0")
   ;;
   ;;this is a lisp made to remove all yellow contents from all
   ;;objects including blocks it will cover paperspace and modelspace
   ;;
   (c:clientprep)
   (command "model")
   ;;
   ;;refreze the outer border that was set on layer 3
   ;;
   (command "layer" "f" "3" "")
   (command "zoom" "e")
   (command "qsave")
   (command "close")
 )
)
(if (= runnum nil)
 (progn
   ;;
   ;;If there are viewports in the drawing the script will continue
   ;;
   ;;ensure the ucs is set to world and the drawing is in top(plan)
   ;;view just a precaution
   ;;
   (setq runnum 0)
   (setq VPC 2)
   (command "model")
   (command "ucs" "w")
   (command "view" "top")
   ;;
   ;;purge and audit drawing to speed up process
   ;;
   (command "purge" "all" "" "n")
   (command "purge" "all" "" "n")
   (command "purge" "all" "" "n")
   (command "audit" "y")
   ;;
   ;;Tilemode is the command that toggles between model and one layout tab
   ;;when set to 1 it is model and when set to 0 is layout we want to be in
   ;;layout to start our conversion process
   ;;
   (command "TILEMODE" "0")
   (command "zoom" "e")
   (command "mspace")
   ;;
   ;;copy everything in modelspace in it's current condition so if
   ;;there are multiple viewports you don't accidently expose some layers
   ;;of references that may have been turned off in other viewports
   ;;
   (command "copybase" "0,0,0" "all" "")
 )
)
;;
;;we make our on counter called vpc to set the viewport to the next
;;one each time we run through the script
;;
(setvar "cvport" vpc)
;;
;;increase viewport counter by one
;;
(setq VPC (1+ (getvar "cvport")))
;;
;;increase run counter by one
;;
(setq runnum (1+ runnum))
;;
;;when trimming objects to the viewport limits the cookie cutter
;;lisp will process blocks but it is slow so we burst
;;the blocks in the viewport ahead of time
burst c -10000000,-10000000 20000000,20000000 
burst c -10000000,-10000000 20000000,20000000 
burst c -10000000,-10000000 20000000,20000000 
;;
;;the cookie cutter will still process all blocks inside
;;the limits or out so we delete everything that does not come
;;into the viewing area
;;
erase all r c -10000000,-10000000 20000000,20000000 
;;
;;we set the layer to defpoints so we can keep our outline as a
;;representation of the original viewport
;;
layer s defpoints 
vp-outline
layer s deleteme123 
group c PlineTemp 
last 
model
;;
;;we use the cookie cutter trim so we can delete all leftover
;;contents including outside cut viewports
;;
cc last 10000000,50 y
;;
;;the cookie cutter trim is nice but does not get all of the
;;lines/objects needing to be trimmed so we use the autocad
;;express tool extrim to clean it up
;;
extrim g plinetemp 10000000,50
;;
;;the var qaflags allows us to explode the entier selection
;;set we need this set to one to accomplish this
;;
(setvar "qaflags" 1)
;;
;;now we create a selection set ss so we can select all dimensions
;;and explode them for the conversion process
;;
(setq ss (ssget '((0 . "dimension")))) all 
;;
;;we only want to explode dimensions if they exist so if there are
;;no dimensions then we do nothing
;;
(if (> (sslength ss) 0)
 (command "._explode" ss "")
)
tilemode 0
;;
;;we make a block of the viewport contents including the outside border
;;this will dramatically increase the chspace time due to being a block
;;
block viewchange 0,0,0
c -10000000,-10000000 20000000,20000000 g plinetemp 
insert viewchange 0,0,0 1  
;;
;;if there is only one viewport the chspace command does not ask which
;;viewport to chspace through so we create an if statement to select
;;the viewport only if there is more than one viewport in the drawing
;;
(if (eq (length (vports)) 2)
   (command "chspace" "c" "-10000000,-10000000" "20000000,20000000" "")
   (command "chspace" "c" "-10000000,-10000000" "20000000,20000000" "" "")
)
;;
;;we explode the block that we made for the chspace command
;;
explode l 
;;
;;now we remove the group called plinetemp this will keep the objects
;;in the group but will delete the group so we can reuse it
;;
group e plinetemp
;;
;;because we made a block of the viewport contents we need to purge
;;that block so it can be reused in each viewport
;;
purge b viewchange n
;;
;;we only want to paste the original model contents if there
;;is another viewport to do if not then we do nothing
;;
(if (< runnum (1- (length (vports))))
 (progn
 (command "model")
 (command "erase" "all" "")
 (command "pasteclip" "0,0,0")
 (command "tilemode" "0")
 (command "mspace"))
)
;;
;;once all viewports have been converted then we want to wrap it up
;;
(if (= runnum (1- (length (vports))))
 (progn
   (command "zoom" "e")
   ;;
   ;;we have kept the polyline border that was a match to the viewport
   ;;outline so we can delete the viewports left in the drawing
   ;;
   (setq ss (ssget "all" '((0 . "viewport")))) 
   (command "erase" "p" "")
   ;;
   ;;we copy everything in paperspace which should be all of the original
   ;;viewing contents that printed on paper some titleblocks had insertion
   ;;points that weren't in the lower left hand corner of the border
   ;;so we copy clip to get a basepoint of that corner
   ;;
   (command "copyclip" "w" "-10,-10" "120,120" "")
   ;;
   ;;we want to delete any objects that were off or frozen in paper
   ;;and in model
   ;;
   (command "laythw")
   (command "layon")
   (command "zoom" "e")
   (command "erase" "all" "")
   (command "model")
   (command "erase" "all" "")
   ;;
   ;;paste the paperspace contents into model
   ;;
   (command "pasteclip" "0,0,0")
   ;;
   ;;there is no more need for layer deleteme123 so we set
   ;;the layer to 0 so the deleteme123 layer is purged out
   ;;
   (command "layer" "s" "0" "")
   (command "purge" "all" "" "n")
   (command "purge" "all" "" "n")
   (command "purge" "all" "" "n")
   (command "zoom" "e")
   ;;
   ;;final audit
   ;;
   (command "audit" "y")
   (command "tilemode" "0")
   ;;
   ;;this is a lisp made to remove all yellow contents from all
   ;;objects including blocks it will cover paperspace and modelspace
   ;;
   (c:clientprep)
   (command "model")
   ;;
   ;;refreze the outer border that was set on layer 3
   ;;
   (command "layer" "f" "3" "")
   (command "zoom" "e")
   (command "qsave")
   (command "close")
 )
 (command "rscript")
)

Client Complete.scr

Posted

Well does it work? :)

 

It sure looks a lot more than a lisp routine than a script file, I didn't realize you could get that much lisp code to run in a script.

Posted

I had to actually do a little tweeking after I submitted it, but yes. If you take a bound drawing with exploded AECObjects then This works great. To get bound drawings with Exploded AECObjects we just run an E-Transmit setup on the drawing set. Then we use a program called script pro that runs the selected script on the drawing set.

Posted

Here is the updated Code

 

;;Script for converting any bound drawing with exploded AECObjects
;;to model and will be "Client Ready" any questions
;;see author Ken B.
;;
;;we start with running some processes only if this is the first
;;pass on the drawing
;;
(if (= runnum nil)
 (progn
   ;;
   ;;ensure we are in paperspace incase the drawing was last saved
   ;;in modelspace and if first run then set viewport q to 2
   ;;
   (command "tilemode" "0")
   (command "pspace")
   ;;
   ;;save a copy of original drawing for conversion process
   ;;as 2004 with "ACAD-" on front of filename
   ;;
   (vl-file-delete (strcat (getvar "DWGPREFIX") "ACAD-" (getvar "DWGNAME")))
   (command "saveas" "2004" (strcat (getvar "dwgprefix") "ACAD-"(getvar "dwgname")))
   ;;
   ;;step one is to unlock all layers so if something that is
   ;;visible was locked it is still
   ;;selectable where frozen or off layers/items will still be unselectable
   ;;
   (command "layer" "u" "*" "")
   ;;
   ;;one variable for trimming and extending is projmode when set to 1 it
   ;;will project the cutting line in al three planes so if there are 3d
   ;;lines/objects the projection of the cutting line will get them too
   ;;
   (setvar "projmode" 1)
   ;;
   ;;another variable for exploding restrics or allows selection sets
   ;;we want to allow the entire set so we set it to one
   ;;
   (setvar "qaflags" 1)
   ;;
   ;;if the layer defpoints doesn't exist then we need to create it
   ;;and ensure that the plot setting is to not plot
   ;;
   (command "layer" "m" "defpoints" "p" "n" "" "")
   ;;
   ;;if the current layer is turned off then the selection set
   ;;can't get objects drawn by the script so a new layer is made
   ;;to ensure that these objects will be selectable
   ;;
   (command "layer" "m" "deleteme123" "")
   ;;
   ;;e-transmit will not do anything with external references that
   ;;were unloaded so we remove all left over external references
   ;;
   (command "XREF" "D" "*")
   ;;
   ;;now we explode all dimensions in paperspace if any
   ;;
   (setq ss (ssget "all" '((0 . "DIMENSION")))) 
   (if (> (sslength ss) 0)
     (command "._explode" ss "")
   )
 )
)
;;
;;if the drawing has no viewports IE electrical one-line diagrams ect...
;;then we just want to convert whats in paper to model so we wrap it up
;;
(if (eq (length (vports)) 1)
 (progn
   (command "zoom" "e")
   ;;
   ;;we copy everything in paperspace which should be all of the original
   ;;viewing contents that printed on paper some titleblocks had insertion
   ;;points that weren't in the lower left hand corner of the border
   ;;so we copy clip to get a basepoint of that corner
   ;;
   (command "copyclip" "c" "-10,-10" "120,120" "")
   ;;
   ;;we want to delete any objects that were off or frozen in paper
   ;;and in model
   ;;
   (command "laythw")
   (command "layon")
   (command "zoom" "e")
   (command "erase" "all" "")
   (command "model")
   (command "zoom" "e")
   (command "erase" "all" "")
   ;;
   ;;paste the paperspace contents into model
   ;;
   (command "pasteclip" "0,0,0")
   ;;
   ;;there is no more need for layer deleteme123 so we set
   ;;the layer to 0 so the deleteme123 layer is purged out
   ;;
   (command "layer" "s" "0" "")
   (command "purge" "all" "" "n")
   (command "purge" "all" "" "n")
   (command "purge" "all" "" "n")
   (command "zoom" "e")
   ;;
   ;;final audit
   ;;
   (command "audit" "y")
   (command "tilemode" "0")
   ;;
   ;;this is a lisp made to remove all yellow contents from all
   ;;objects including blocks it will cover paperspace and modelspace
   ;;
   (c:clientprep)
   (command "model")
   ;;
   ;;refreze the outer border that was set on layer 3
   ;;
   (command "layer" "f" "3" "")
   (command "zoom" "e")
   (command "qsave")
   (command "close")
 )
)
(if (= runnum nil)
 (progn
   ;;
   ;;If there are viewports in the drawing the script will continue
   ;;
   ;;ensure the ucs is set to world and the drawing is in top(plan)
   ;;view just a precaution
   ;;
   (setq runnum 0)
   (setq VPC 2)
   (command "model")
   (command "ucs" "w")
   (command "view" "top")
   ;;
   ;;purge and audit drawing to speed up process
   ;;
   (command "purge" "all" "" "n")
   (command "purge" "all" "" "n")
   (command "purge" "all" "" "n")
   (command "audit" "y")
   ;;
   ;;Tilemode is the command that toggles between model and one layout tab
   ;;when set to 1 it is model and when set to 0 is layout we want to be in
   ;;layout to start our conversion process
   ;;
   (command "TILEMODE" "0")
   (command "zoom" "e")
   (command "mspace")
   ;;
   ;;copy everything in modelspace in it's current condition so if
   ;;there are multiple viewports you don't accidently expose some layers
   ;;of references that may have been turned off in other viewports
   ;;
   (command "copybase" "0,0,0" "all" "")
 )
)
;;
;;we make our on counter called vpc to set the viewport to the next
;;one each time we run through the script
;;
(setvar "cvport" vpc)
;;
;;increase viewport counter by one
;;
(setq VPC (1+ (getvar "cvport")))
;;
;;increase run counter by one
;;
(setq runnum (1+ runnum))
;;
;;when trimming objects to the viewport limits the cookie cutter
;;lisp will process blocks but it is slow so we burst
;;the blocks in the viewport ahead of time
burst c -10000000,-10000000 20000000,20000000 
burst c -10000000,-10000000 20000000,20000000 
burst c -10000000,-10000000 20000000,20000000 
;;
;;the cookie cutter will still process all blocks inside
;;the limits or out so we delete everything that does not come
;;into the viewing area
;;
erase all r c -10000000,-10000000 20000000,20000000 
;;
;;now we create a selection set ss so we can select all dimensions
;;and explode them for the conversion process
;;
(setq ss (ssget '((0 . "dimension")))) all 
;;
;;we only want to explode dimensions if they exist so if there are
;;no dimensions then we do nothing
;;
(if (> (sslength ss) 0)
 (command "._explode" ss "")
)
(setvar "qaflags" 0)
;;
;;we set the layer to defpoints so we can keep our outline as a
;;representation of the original viewport
;;
layer s defpoints 
vp-outline
layer s deleteme123 
group c PlineTemp 
last 
model
;;
;;we use the cookie cutter trim so we can delete all leftover
;;contents including outside cut viewports
;;
cc last 10000000,50 y y
;;
;;the cookie cutter trim is nice but does not get all of the
;;lines/objects needing to be trimmed so we use the autocad
;;express tool extrim to clean it up
;;
extrim g plinetemp 10000000,50
;;
;;the var qaflags allows us to explode the entier selection
;;set we need this reset to one to accomplish this
;;
(setvar "qaflags" 1)
tilemode 0
;;
;;we make a block of the viewport contents including the outside border
;;this will dramatically increase the chspace time due to being a block
;;
block viewchange 0,0,0
c -10000000,-10000000 20000000,20000000 g plinetemp 
insert viewchange 0,0,0 1  
;;
;;if there is only one viewport the chspace command does not ask which
;;viewport to chspace through so we create an if statement to select
;;the viewport only if there is more than one viewport in the drawing
;;
(if (eq (length (vports)) 2)
   (command "chspace" "c" "-10000000,-10000000" "20000000,20000000" "")
   (command "chspace" "c" "-10000000,-10000000" "20000000,20000000" "" "")
)
;;
;;we explode the block that we made for the chspace command
;;
explode l 
;;
;;now we remove the group called plinetemp this will keep the objects
;;in the group but will delete the group so we can reuse it
;;
group e plinetemp
;;
;;because we made a block of the viewport contents we need to purge
;;that block so it can be reused in each viewport
;;
purge b viewchange n
;;
;;we only want to paste the original model contents if there
;;is another viewport to do if not then we do nothing
;;
(if (< runnum (1- (length (vports))))
 (progn
 (command "model")
 (command "erase" "all" "")
 (command "pasteclip" "0,0,0")
 (command "tilemode" "0")
 (command "mspace"))
)
;;
;;once all viewports have been converted then we want to wrap it up
;;
(if (= runnum (1- (length (vports))))
 (progn
   (command "zoom" "e")
   ;;
   ;;we have kept the polyline border that was a match to the viewport
   ;;outline so we can delete the viewports left in the drawing
   ;;
   (setq ss (ssget "all" '((0 . "viewport")))) 
   (command "erase" "p" "")
   ;;
   ;;we copy everything in paperspace which should be all of the original
   ;;viewing contents that printed on paper some titleblocks had insertion
   ;;points that weren't in the lower left hand corner of the border
   ;;so we copy clip to get a basepoint of that corner
   ;;
   (command "copyclip" "w" "-10,-10" "120,120" "")
   ;;
   ;;we want to delete any objects that were off or frozen in paper
   ;;and in model
   ;;
   (command "laythw")
   (command "layon")
   (command "zoom" "e")
   (command "erase" "all" "")
   (command "model")
   (command "erase" "all" "")
   ;;
   ;;paste the paperspace contents into model
   ;;
   (command "pasteclip" "0,0,0")
   ;;
   ;;there is no more need for layer deleteme123 so we set
   ;;the layer to 0 so the deleteme123 layer is purged out
   ;;
   (command "layer" "s" "0" "")
   (command "purge" "all" "" "n")
   (command "purge" "all" "" "n")
   (command "purge" "all" "" "n")
   (command "zoom" "e")
   ;;
   ;;final audit
   ;;
   (command "audit" "y")
   (command "tilemode" "0")
   ;;
   ;;this is a lisp made to remove all yellow contents from all
   ;;objects including blocks it will cover paperspace and modelspace
   ;;
   (c:clientprep)
   (command "model")
   ;;
   ;;refreze the outer border that was set on layer 3
   ;;
   (command "layer" "f" "3" "")
   (command "zoom" "e")
   (command "qsave")
   (command "close")
 )
 (command "rscript")
)

Posted

The clientprep is a custom command that is actually named after the client (I changed as to avoid negative reflection). that was made by one of the people at my workplace that are supposed to be the ones doing this kind of stuff but aren't quick.

 

Because it's a script we can use it with the script pro program. If it was a lisp I have no idea how I would have accomplished some of the functions I did

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