Jump to content

Recommended Posts

Guest Brian_MMC
Posted

I’m looking for a LSP or program that will do the following…

Open a .dwg from a section set.

QSELECT all Block References

EXPLODE

QSELECT all Block References

EXPLODE

QSELECT all Block References

EXPLODE

SAVE

CLOSE

Repeat through Selection set.

Close Program

If anyone can help me with this or point me in the rightdirection it would be greatly appreciated.

Thanks in advance for sharing your talents.

Brian

Posted (edited)

Try this :

 

(defun c:3xselexp-cl ( / qaf ss ent enta ) (vl-load-com)
 (setq qaf (getvar 'qaflags))
 (setvar 'qaflags 1)
 (repeat 3
   (setq ss (ssget "_X" '((0 . "INSERT")) ))
   (repeat (setq ssn (sslength ss))
     (setq enta (vlax-ename->vla-object (ssname ss (setq ssn (1- ssn)) )))
     (if (vlax-property-available-p enta 'Path)
       (progn
         (setq ent (vlax-vla-object->ename enta))
         (ssdel ent ss)
       )
     )
   )
   (if ss
     (command "_.explode" ss "")
   )
 )
 (setvar 'qaflags qaf)
(princ)
)

(defun c:nxop3xexcl ( lspf / scrf filens path )
 (setq scrf (open "c:/opexpclall.scr" "w"))
 (setq filens (vl-directory-files (setq path (vl-filename-directory (getfiled "Pick one dwg in dirctory where are all other dwgs stored" "" "dwg" )) "*.dwg"))
 (repeat (strlen path)
   (setq path (vl-string-subst (chr 47) (chr 92) path))
 )
 (foreach f filens
   (progn 
     (princ "_.open" scrf)
     (princ "\n" scrf)
     (prin1 (strcat path (chr 47) f) scrf)
     (princ "\n" scrf)
     (princ "(setq lspflg T)" scrf)
     (princ "\n" scrf)
     (princ (strcat "(load \"" lspf "\")") scrf)
     (princ "\n" scrf)
     (princ "3xselexp-cl" scrf)
     (princ "\n" scrf)
     (princ "_.qsave" scrf)
     (princ "\n" scrf)
   )
 )
 (princ "_.shell" scrf)
 (princ "\n" scrf)
 (princ "erase c:\\opexpclall.scr" scrf)
 (princ "\n" scrf)
 (princ "_.closeall" scrf)
 (princ "\n" scrf)
 (close scrf)
 (command "_.script" "c:/opexpclall.scr")
(princ)
)

(if (eq lspflg nil)
 (progn
   (setq lspf (getfiled "SELECT LSP FILE THAT YOU JUST LOADED" "" "lsp" )
   (repeat (strlen lspf)
     (setq lspf (vl-string-subst (chr 47) (chr 92) lspf))
   )
   (c:nxop3xexcl lspf)
 )
)
(princ)

M.R.

Edited by marko_ribar
code changed
Guest Brian_MMC
Posted

Marko_ribar,

First off thank you for your help. I’m not sure what I’m doing wrong but I keep getting thefollowing.

Command: AP

APPLOAD 3xselexp-cl.lsp successfully loaded.

Command: ; error: bad argument type: FILE nil

Command:

I’ve tried a few different files and locations and get thesame thing, Any ideas?

Posted (edited)

Try to save my code in different file than AP.lsp (AP is alias for appload command and I never used appload - instead used (load "..."))... I have my code under : nxop3xexcl.lsp... You should just after loading lsp select firstly again lsp that you loaded and then select one *.dwg in directory where all others *.dwg for open-3xselectexplode are stored... I've checked code on 2 my PC's and it works even on ACAD 2008... Honestly I don't quite know from where error occurs...

 

M.R.

Edited by marko_ribar
Posted

code changed in first post...

 

M.R.

Guest Brian_MMC
Posted (edited)

After doing some is digging with Steve. He is guessing it’s something to do with the Administration rights on my computer or the anti-virus software. Not allowing the system to create the opexpclall.scr on the C:\ drive while running through the LSP. He made a work around to have it mike and findthe file in my temp folder and its working like a champ. Thanks for the help guys.

Edited by Brian_MMC
Posted

I've updated my first post, and in addition I've made code that will save *.dwg only if blocks are found within... So here is code :

 

(defun c:3xselexp-cl ( / qaf ss ent enta ) (vl-load-com)
 (setq qaf (getvar 'qaflags))
 (setvar 'qaflags 1)
 (repeat 3
   (setq ss (ssget "_X" '((0 . "INSERT")) ))
   (repeat (setq ssn (sslength ss))
     (setq enta (vlax-ename->vla-object (ssname ss (setq ssn (1- ssn)) )))
     (if (vlax-property-available-p enta 'Path)
       (progn
         (setq ent (vlax-vla-object->ename enta))
         (ssdel ent ss)
       )
     )
   )
   (if ss 
     (if (> (sslength ss) 0)
       (progn
         (command "_.explode" ss "")
         (setq expflg T)
       )
     )
   )
 )
 (setvar 'qaflags qaf)
(princ)
)

(defun c:nxop3xexcl ( lspf / scrf filens path )
 (setq scrf (open "c:/opexpclall.scr" "w"))
 (setq filens (vl-directory-files (setq path (vl-filename-directory (getfiled "Pick one dwg in dirctory where are all other dwgs stored" "" "dwg" )) "*.dwg"))
 (repeat (strlen path)
   (setq path (vl-string-subst (chr 47) (chr 92) path))
 )
 (foreach f filens
   (progn 
     (princ "_.open" scrf)
     (princ "\n" scrf)
     (prin1 (strcat path (chr 47) f) scrf)
     (princ "\n" scrf)
     (princ "(setq lspflg T)" scrf)
     (princ "\n" scrf)
     (princ (strcat "(load \"" lspf "\")") scrf)
     (princ "\n" scrf)
     (princ "3xselexp-cl" scrf)
     (princ "\n" scrf)
     (princ "(if (eq expflg T) (command \"_.qsave\"))" scrf)
     (princ "\n" scrf)
   )
 )
 (princ "_.shell" scrf)
 (princ "\n" scrf)
 (princ "erase c:\\opexpclall.scr" scrf)
 (princ "\n" scrf)
 (princ "_.closeall" scrf)
 (princ "\n" scrf)
 (close scrf)
 (command "_.script" "c:/opexpclall.scr")
(princ)
)

(if (eq lspflg nil)
 (progn
   (setq lspf (getfiled "SELECT LSP FILE THAT YOU JUST LOADED" "" "lsp" )
   (repeat (strlen lspf)
     (setq lspf (vl-string-subst (chr 47) (chr 92) lspf))
   )
   (c:nxop3xexcl lspf)
 )
)
(princ)

 

So, this is my final result... Had some problems with (command "_.explode" ss) (while (not (eq (getvar 'cmdactive) 0)) (command ""))

 

Hope this finally helps... If you still can't create and delete file on root of c:\ drive, just change drive to d:\, but be sure that you changed letter in all places where c:\opexpclall.scr file occurs...

 

M.R. (Marko Ribar, d.i.a. - graduated engineer of architecture)

Posted

I hope you won't be sending the dwg to anyone else once you have done your architecture component. Exploded blocks are highly frowned upon by others. Exception being if you use a vertical product and have to explode its dynamic ability so others can view it.

Posted
I've updated my first post, and in addition I've made code that will save *.dwg only if blocks are found within... So here is code :

 

(defun c:3xselexp-cl ( / qaf ss ent enta ) (vl-load-com)
 (setq qaf (getvar 'qaflags))
 (setvar 'qaflags 1)
 (repeat 3
   (setq ss (ssget "_X" '((0 . "INSERT")) ))
   (repeat (setq ssn (sslength ss))
     (setq enta (vlax-ename->vla-object (ssname ss (setq ssn (1- ssn)) )))
     (if (vlax-property-available-p enta 'Path)
       (progn
         (setq ent (vlax-vla-object->ename enta))
         (ssdel ent ss)
       )
     )
   )
   (if ss 
     (if (> (sslength ss) 0)
       (progn
         (command "_.explode" ss "")
         (setq expflg T)
       )
     )
   )
 )
 (setvar 'qaflags qaf)
(princ)
)

(defun c:nxop3xexcl ( lspf / scrf filens path )
 (setq scrf (open "c:/opexpclall.scr" "w"))
 (setq filens (vl-directory-files (setq path (vl-filename-directory (getfiled "Pick one dwg in dirctory where are all other dwgs stored" "" "dwg" )) "*.dwg"))
 (repeat (strlen path)
   (setq path (vl-string-subst (chr 47) (chr 92) path))
 )
 (foreach f filens
   (progn 
     (princ "_.open" scrf)
     (princ "\n" scrf)
     (prin1 (strcat path (chr 47) f) scrf)
     (princ "\n" scrf)
     (princ "(setq lspflg T)" scrf)
     (princ "\n" scrf)
     (princ (strcat "(load \"" lspf "\")") scrf)
     (princ "\n" scrf)
     (princ "3xselexp-cl" scrf)
     (princ "\n" scrf)
     (princ "(if (eq expflg T) (command \"_.qsave\"))" scrf)
     (princ "\n" scrf)
   )
 )
 (princ "_.shell" scrf)
 (princ "\n" scrf)
 (princ "erase c:\\opexpclall.scr" scrf)
 (princ "\n" scrf)
 (princ "_.closeall" scrf)
 (princ "\n" scrf)
 (close scrf)
 (command "_.script" "c:/opexpclall.scr")
(princ)
)

(if (eq lspflg nil)
 (progn
   (setq lspf (getfiled "SELECT LSP FILE THAT YOU JUST LOADED" "" "lsp" )
   (repeat (strlen lspf)
     (setq lspf (vl-string-subst (chr 47) (chr 92) lspf))
   )
   (c:nxop3xexcl lspf)
 )
)
(princ)

 

So, this is my final result... Had some problems with (command "_.explode" ss) (while (not (eq (getvar 'cmdactive) 0)) (command ""))

 

Hope this finally helps... If you still can't create and delete file on root of c:\ drive, just change drive to d:\, but be sure that you changed letter in all places where c:\opexpclall.scr file occurs...

 

M.R. (Marko Ribar, d.i.a. - graduated engineer of architecture)

 

If you are going to go through the trouble to step through the selection set, just use vla-explode on them, or step through the blocks and create a list of xref names to ignore in your ssget filter.

Guest Brian_MMC
Posted
I hope you won't be sending the dwg to anyone else once you have done your architecture component. Exploded blocks are highly frowned upon by others. Exception being if you use a vertical product and have to explode its dynamic ability so others can view it.

 

The files that this is being used on is an Revit export to CAD. When other Revit files are linkedin they become Block and pick up the layer 0. The same thing happens with the family’swith in the base file and the linked file (Blocks in Blocks). Once the blocks have the layer 0 printing becomes a pane as far as freezingthe correct layers without going to a lot of work. I would go through and just scrub thedrawings to get the look we are going for but we get a new export weekly andthere are about 300 drawings we receive.

 

Thank your for the inciteon the matter though.

Posted
If you are going to go through the trouble to step through the selection set, just use vla-explode on them, or step through the blocks and create a list of xref names to ignore in your ssget filter.

 

I remembered why I like to use more often "_.explode" instead of vla-explode... Its because after vla-explode you can't obtain objects you just exploded... With "_.explode" you can easily get them by (ssget "_P")... But in this case, you're probably in wright as usually you are... Nevertheless, the code would be little shorter and more efficient, but it would do the job like this one posted...

Have no time to experiment too much, maybe in some other occasion...

Thanks for your witty remark and good luck in your next activities, Alan...

Best regards, M.R.

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