Ok, I stared this earlier but the thread took off faster than I could write this
so I held off posting. This is my feeble attempt at explaining how this lisp could
be written. Note that there are many ways to code so I am attempting to take a very
basic approach to this routine. This is what I have so far & lack time to finish so
please someone step in & complete the routine & expiation and correct any mistakes
I have made. Also fill in any gaps I left. <please excuse the spelling & grammar too>
joker you will need do create a function you can call from the command line.
It may look like this
(defun c:ReBlock()
; your code goes here
)
Note that for every opening parentheses there must be a closing parenthesis.
See the help file for explanation of a defun
You can call ReBlock from the command line, It won't do anything yet but you will fix that.
Also note that the semicolon starts a comment
From the Help File:
; Single-Semicolon Starts at the comment-column position, as defined by the
"Single-Semicolon comment indentation" format option.
;; Current-Column The comment appears starting on a new line, indented at the
same level as the last line of program code.
;;; Heading or 0-Column Appears on a new line, without indentation.
So this is what I often do, wrap the pseudo code with the function as Tim did earlier.
He picked ReBlock as the function name but you can pick your own name. Obviously it
should be meaningful to you.
(defun c:ReBlock()
;User picks block to export
;Insert the block at 0,0
;Explode the block
;Collect the new entities in a list
;Change all the entities to color of layer if color ByLayer
;Change all the entities to layer zero
;wblock out the explode pieces, ? any user input ?
;Delete the explode pieces
)
Now you start adding code to preform the tasks described. Note that the pseudo code may
change as you develop your routine & discover things you did not consider in the beginning.
That's just part of the process, for me that is.
Lets add the code that tim provided to explode & collect. He will explain it later.
Let me say that there are some error prevention & recovery code that you will want but
to keep it simple at first just stick to the basic pseudo code requirements first.
(defun c:ReBlock()
;User picks block to export
;Insert the block at 0,0
;Explode the block and Collect the new entities in a list
(setq EntList
(mapcar 'vlax-vla-object->ename
(vlax-invoke (vlax-ename->vla-object Ent) 'Explode)
)
)
;Change all the entities to color of layer if color ByLayer
;Change all the entities to layer zero
;wblock out the explode pieces, ? any user input ?
;Delete the explode pieces
)
OK, how about the first item, picking the block to work with.
Do you see how that may be accomplished?
Looking at Tim's full version we can barrow this:
(setq ss (ssget ":E:S" '((0 . "INSERT"))))
That's different in that I added ":E:S" which limits the selection to one object.
This code gives control to the user to select object(s) & adds there Entity Name to a 'selection set'
This selection set is stored in the variable named ss. In our case here it will only contain one
item. In Tim's code it can contain many items. (setq ss (ssget '((0 . "INSERT"))))
The '((0 . "INSERT")) is a filter making sure that only INSERT's can be selected. That is the label
given to blocks that exist in model or paperspace.
So here is the updated code:
(defun c:ReBlock()
;User picks block to export
(setq ss (ssget ":E:S" '((0 . "INSERT"))))
;Insert the block at 0,0
;Explode the block and Collect the new entities in a list
(setq EntList
(mapcar 'vlax-vla-object->ename
(vlax-invoke (vlax-ename->vla-object Ent) 'Explode)
)
)
;Change all the entities to color of layer if color ByLayer
;Change all the entities to layer zero
;wblock out the explode pieces, ? any user input ?
;Delete the explode pieces
)
Now we need the "Entity Name" of that insert. We get that with this:
(setq ename (ssname ss 0))
So ename is the variable now holding the item entity name the user selected.
To get the block name we look at DXF code 2 like this:
(setq blkname (cdr (assoc 2 (entget ename))))
WE can use it to insert a copy of that block by using the INSERT command.
(command "_.INSERT" blkname '(0.0 0.0 0.0) 1 1 1 0)
Here is the code so far.
(defun c:ReBlock()
;User picks block to export
(setq ss (ssget ":E:S" '((0 . "INSERT"))))
;Get the block name from the entity list
(setq ename (ssname ss 0))
(setq blkname (cdr (assoc 2 (entget ename))))
;Insert the block at 0,0 and save its ename in variable ent
(command "_.INSERT" blkname '(0.0 0.0 0.0) 1 1 1 0)
(setq ent (entlast))
;Explode the block and Collect the new entities in a list
(setq EntList
(mapcar 'vlax-vla-object->ename
(vlax-invoke (vlax-ename->vla-object Ent) 'Explode)
)
)
;Change all the entities to color of layer if color ByLayer
;Change all the entities to layer zero
;wblock out the explode pieces, ? any user input ?
;Delete the explode pieces
)