Explode All not exploding all

Explode All not exploding all

sjelen
Contributor Contributor
623 Views
10 Replies
Message 1 of 11

Explode All not exploding all

sjelen
Contributor
Contributor

Hello all!

 

I'm trying to perform what I think is a simple few commands in AutoCAD - I have this placed in my C# file to run through script. If I run it manually in AutoCAD it will explode and extrude which is great but sometimes it only will explode some of the objects but not all. I'm using it on a DWG export from Revit of ACT Grids and it works great a lot of the time but again sometimes it doesn't explode them all and I have to manually go in and explode the object that didn't explode. 

 

I was wondering what is the reason for this and if I can adjust the code to be more robust to check if all objects have been exploded and if so then move on to extrude and if not to explode them again until all are exploded and then I can extrude. Hope someone can help! Thank you! 

 

(defun c:JoinExtrudeAll ( )

  ;; Set view to top

  (command ""_VPOINT"" ""0,0,1"")

 

  ;; Set to layer 0 to avoid lock

  (command ""_LAYER"" ""S"" ""0"" """")

 

  ;; Try deleting A-CLNG layer

  (command ""_LAYDEL"" ""N"" ""A-CLNG"" """" ""Y"" """")

 

  ;; First explode attempt

  (command ""_EXPLODE"" ""ALL"")

 

  ;; Extrude everything

  (command ""_EXTRUDE"" ""ALL"" """" ""2"")

 

  ;; Save and close

  (command ""_QSAVE"")

  (command ""_QUIT"")

  (princ)

)

0 Likes
624 Views
10 Replies
Replies (10)
Message 2 of 11

paullimapa
Mentor
Mentor

if you can isolate what objects fail to explode that would be a good start point.

if you're referring to exploding all blocks including nested ones then you may want to look at @hmsilvamore complex explode lisp function here:

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/recursive-explode-lisp/td-p/5699939


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 11

Kent1Cooper
Consultant
Consultant

This may not solve your problem, but you shouldn't have double double-quotes around everything.  It may work for some entries, but I suspect you're going to get two Enters where you intend only one, which would certainly cause trouble, if not necessarily this particular trouble.

Kent Cooper, AIA
0 Likes
Message 4 of 11

Moshe-A
Mentor
Mentor

@sjelen hi,

 

First,

keep in mind that blocks can have nested blocks so calling explode on all objects will explode them at the first level and to deeply explode more, you have to call it again so this one requires a loop.

 

Second,

if you already have a pline it will be exploded too...do you want that?! maybe filter the selection to blocks only.

 

thirdly,

for the extrude, filter selection for the objects you want to extrude.

 

Moshe

 

0 Likes
Message 5 of 11

sjelen
Contributor
Contributor

Good morning Kent - 

 

I am using double quotes because it being inside my C# file if I have just single quotes it messes with a lot of parts of the code and doesn't "close" portions. But thinking about it now, maybe I wrap the whole Lisp file in quotes and maybe that will resolve the issue of using double quotes inside each function. I did also check my Lisp file as it gets saved each time the C# command is run and it appears that it's only single quotes in there as it doesn't pick up the double from the C# file. I will try wrapping it all in quotes just as a test as well. 

 

Thanks

0 Likes
Message 6 of 11

sjelen
Contributor
Contributor

Good morning Moshe-A - I tried figuring out how to write that loop but I'm having no luck. Would you be able to help me with that?

 

I had tried running Explode twice but found that when everything exploded on the first go around and ran the second time I would get an error and the extrude command would not run.

 

Thank you 

0 Likes
Message 7 of 11

BlackBox_
Advisor
Advisor

@sjelen trying to understand why you're hard-coding a Script in LISP, within a C# .NET plugin (within your VS project/solution)?

 

All of this can be done from C# - even if you didn't want to code the overhead of doing this in API, you can still invoke the necessary commands from .NET API via SendStringToExecute(), etc as needed. 

 

In any event, here's how to explode modelspace Blocks in a loop (in LISP): 

(while (setq ss (ssget "_x" '((0 . "INSERT")(410 . "Model"))))
  (command "._explode" ss)
)

 

Lastly, if you're wanting to batch process 2+ drawings at the same time, instead call Core Console to process each drawing in parallel, using your .SCR (or code this as a C# CommandMethod, NETLOAD your assembly & invoke).

 

HTH


"How we think determines what we do, and what we do determines what we get."

Sincpac C3D ~ Autodesk Exchange Apps

0 Likes
Message 8 of 11

sjelen
Contributor
Contributor

Dang ok, I'd love to learn more about how to incorporate it in the C# opposed to having the program execute a scr. file which then runs the Lisp. I'll try the code you sent and give that a try first as I've been able to make it work(mostly) but definitely would like to understand more about what you're describing. 

Would you want to discuss that further here or a separate discussion?

 

Thank you! 

0 Likes
Message 9 of 11

BlackBox_
Advisor
Advisor

More information here first would be helpful; there's already a lot of talented folks participating before I chimed in. 

 

Also, if you didn't know that you could do this all from C#, perhaps it would be prudent to first exhaust the Script/LISP level of capability, before jumping to doing this all in C#. :beer:

 

Others may have additional questions, but I'm particularly interested to know if you're doing this on active drawing only, or multiple drawings. 

 

If the former, cull the Script/LISP from your C# plugin, save it within your SFSP and simply use them as-is (with any enhancements made here, of course) and load/call them as you would any normal Script/LISP on the active document. 

 

If the latter, there are multiple ways to approach batch processing... the fastest I've seen, is to use Core Console to process multiple drawings in parallel.

 

Here's an example, using LISP + DOSLib, that loads Core Console using the active session's Profile info (code copied from a 2018 post in another forum that uses BB formatting, revise as needed): 

(vl-load-com)

(defun c:SCRM() (c:ScriptMultiple))
(defun c:ScriptMultiple (/ app flag dwgs dwgPath script cprofile)
;;;
;;;  AcCoreConsole.exe [/i <input dwg>] /s <script>[/product <product>] [/l <language>]
;;;  [/isolate <userid> <userDataFolder>] [/readonly] [/p[rofile] <profile>] 
;;;
  (if
    (and
      (setq app (findfile "accoreconsole.exe"))
      (setq flag (dos_version))
      (setq dwgs
             (dos_getfilem
               "Select drawing(s) to process:"
               (if *Dwg_LastPath*
                 *Dwg_LastPath*
                 (getvar 'dwgprefix)
               )
               "Drawing files (*.dwg)|*.dwg||"
             )
      )
      (setq *Dwg_LastPath* (car dwgs))
      (setq dwgPath *Dwg_LastPath*)
      (setq dwgs (cdr dwgs))
      (setq script
             (dos_getfiled
               "Select a Script to run:"
               (if *Script_LastPath*
                 *Script_LastPath*
                 "[COLOR="#FF0000"]C:\\ProgramData\\Autodesk\\C3D 2019\\BatchSaveTool\\Scripts[/COLOR]"
               )
               "Script (*.scr)|*.scr||"
             )
      )
      (setq *Script_LastPath* (vl-filename-directory script))
      (setq cprofile (getvar 'cprofile))
    )
     (progn
       (foreach dwg dwgs
         (startapp
           (strcat
             "\""
             app
             "\" /i \""
             dwgPath
             dwg
             "\" /s \""
             script
             "\" /product \"[COLOR="#FF0000"]C3D[/COLOR]\" /p \""
             cprofile
             "\""
           )
         )
       )
     )
     (cond
       (dwgs (prompt "\n** No script selected ** \n"))
       (flag (prompt "\n** No drawing(s) selected ** \n"))
       (app (prompt "\n** DOSLib required ** \n"))
       ((prompt
          "\n** Unable to find \"AcCoreConsole.exe\" in support paths ** \n"
        )
       )
     )
  )
  (princ)
)

 

Here's an example, using Windows Shell Menu from File Explorer (outside of CAD), to right click --> plot DWG to PDF, using Autopublish (assuming you've set that up for PDF, etc): 


@BlackBox_ wrote:

<snip>

 

What takes PUBLISH (written in ARX not .NET) 30+ minutes to produce PDFs, only takes +/- 3 minutes using Core Console with this Windows Shell menu (and a lot less code! Haha): 

 

** The size and configuration of a plan set determine the relative time each takes (few multi-layout drawings vs many single-layout drawings, the latter actually takes less time to process).

 

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\RightClickDwgToPdf]
@="2026 DWG to PDF"
"AppliesTo"=".dwg"
; "Icon"="C:\\Program Files\\Autodesk\\AutoCAD 2026\\accoreconsole.exe"
"HasLUAShield"=""
"Position"="Bottom"

[HKEY_CLASSES_ROOT\*\shell\RightClickDwgToPdf\command]
@="\"C:\\Program Files\\Autodesk\\AutoCAD 2026\\accoreconsole.exe\" /i \"%1\" /ld \"C:\\Program Files\\Autodesk\\AutoCAD 2026\\AecBase.dbx\" /p \"<YourProfileHere>\" /product \"C3D\" /language \"en-US\" /s \"C:\\<YourFilePathHere>\\RightClickDwgToPdf.scr\""

 

Here's the dependent Script: 

;; reload layer state, set other sysvars
(setvar 'automaticpub 1)
(command ".QSAVE")

 

Cheers


 

 


"How we think determines what we do, and what we do determines what we get."

Sincpac C3D ~ Autodesk Exchange Apps

0 Likes
Message 10 of 11

sjelen
Contributor
Contributor

@BlackBox_  thank you for sending that over. I must be doing something wrong, I can't get it to run over the elements. Am I supposed to nest it in my explode command or does it completely replace my Explode command? I've tried it both ways on my end and I'm not seeing it work correctly. Would you be able to show me how it falls into my code I provided earlier?

 

Thank you!

0 Likes
Message 11 of 11

BlackBox_
Advisor
Advisor

@sjelen wrote:

@BlackBox_  thank you for sending that over. I must be doing something wrong, I can't get it to run over the elements. Am I supposed to nest it in my explode command or does it completely replace my Explode command? I've tried it both ways on my end and I'm not seeing it work correctly. Would you be able to show me how it falls into my code I provided earlier?

 

Thank you!


No worries; here's a working LISP (to be loading into AutoCAD directly, not pasted into your C# VS solution): 

 

(defun c:JoinExtrudeAll (/ ss)
  
  ;; Set view to top
  (command "._VPOINT" "0,0,1")

  ;; Set to layer 0 to avoid lock
  (command "._-LAYER" "_s" "0" "_u" "*" "")

  ;; Try deleting A-CLNG layer
  (if (tblsearch "layer" "A-CLNG")
    (command "._-LAYDEL" "_n" "A-CLNG" "" "_y" "")
  )

  ;; First explode attempt
  (command "._EXPLODE" "ALL")

  ;; Loop to explode all Blocks
  (while (setq ss (ssget "_x" '((0 . "INSERT") (410 . "Model"))))
    (command "._explode" ss)
  )

  ;; Extrude everything
  (command "._EXTRUDE" "ALL" "" "2")
  
  ;; Save and close
  (command "._QSAVE")
  (command "._QUIT")
  (princ)
)

  


"How we think determines what we do, and what we do determines what we get."

Sincpac C3D ~ Autodesk Exchange Apps

0 Likes