I've written the code to replace a polyline with an edited version of itself (removed 0 length sections), but I'm having trouble figuring out how to replace the polyline when it's inside of a block.
I have a number of blocks in the drawing, and I need to check them and replace if necessary.
Can someone share how to loop through the blocks in the block table, open the block, and how to save the block after replacing the polyline?
Thanks
@mgorecki wrote:
.... to replace a polyline with an edited version of itself (removed 0 length sections), but I'm having trouble figuring out how to replace the polyline when it's inside of a block. ....
Clarify some things....
Are you talking about taking an already-edited version of a specific Polyline and putting it into the Block definition in place of a specific Polyline that hasn't been fixed? Or are you talking about running the remove-0-length editing process on a Polyline inside the Block definition? That is, actual replacement vs. editing in place? I don't know how to do the former other than with a BEDIT or REFEDIT command, which would involve User work in each Block definition, but I think I know how to approach the latter in an automated way.
Also, if the latter, is it a particular Polyline that has to be identified [harder], or would you want to just run the remove-0-length process on any and all Polylines that may be in the Block definition [easier]? If a particular one, how can it be distinguished from others? For instance, is it on a Layer that no other Polyline(s) will be on [easier]? Or does it have a specific configuration that must be detected somehow [harder]?
In the case of a specific shape, and if it is always positioned in the same relationship to the insertion base point in every Block in which it occurs, the editing-in-place could be done as a mere replacement of the coordinates listing, and maybe some more pieces of entity data [e.g. if there are varying widths], without having to actually run the remove-0-length process on it.
@Kent1Cooper , all your doubts will be cleared if @mgorecki Upload a sample.dwg and also his up today LISP.
Hello,
I want the program to open each block in a user selected window (because there are a number of other blocks that the program can ignore).
When it opens the block, it will get the polyline and check for 0 length sections. If there are any, the program will get the coordinates of the vertices and skip the 0 length section and either erase and create a new polyline, or update the existing with an entmod (I haven't decide which one to go with).
Then it would save the block and go on to the next one.
The drawing is created by a 3rd party software and sometimes the blocks contain bad polylines.
I have the code written already that examines the polyline and will get the coordinates. I just need to be sure I'm actually making the changes.
Thanks for looking into this.
@mgorecki wrote:
.... it will get the polyline and check for 0 length sections. If there are any, the program will get the coordinates of the vertices and skip the 0 length section and either erase and create a new polyline, or update the existing with an entmod (I haven't decide which one to go with).
....
I think you don't need a routine to do that. With appropriate settings checked, OVERKILL will eliminate zero-length segments from Polylines, and without any need to check whether there are any.
It's possible that there may be duplicate polylines on top of each other. I was also going to write the function to remove the extra. After that it would remove the zero-length sections from the remaining one.
I didn't know about the Overkill command, I'll have to look into it. Thanks.
hi @Kent1Cooper , I test Overkill at this dwg , It did not kill the dup points at the Pline at the block reference.
@mgorecki wrote:I've written the code to replace a polyline with an edited version of itself (removed 0 length sections), but I'm having trouble figuring out how to replace the polyline when it's inside of a block.
I have a number of blocks in the drawing, and I need to check them and replace if necessary.
Can someone share how to loop through the blocks in the block table, open the block, and how to save the block after replacing the polyline?
Thanks
This is a sample of how to step into block definition.
For demonstration, the lisp is changing the color of each polyline to red, I hope you can add your existing code to this.
(defun c:BLUPD ( / acdoc blocks ss i b n l a1 a2 p d)
(setq acdoc (vla-get-activedocument (vlax-get-acad-object))
blocks (vla-get-blocks acdoc))
(if
(setq ss (ssget '((0 . "INSERT"))))
(repeat (setq i (sslength ss))
(setq b (vlax-ename->vla-object (ssname ss (setq i (1- i))))
n (vlax-get b (if (vlax-property-available-p b 'EffectiveName) 'EffectiveName 'Name))
)
(if
(vl-position n l)
(vla-update b)
(progn
(vlax-for obj (vla-item blocks n)
(if
(and
(eq (vla-get-objectname obj) "AcDbPolyline")
;more conditions
)
(progn
;(vlax-put obj 'coordinates list_of_new_points)
; + vla-setbulge obj if necessary
(vla-put-color obj acred)
)
)
)
(vla-update b)
(setq l (cons n l))
)
)
)
)
(vla-regen acdoc acActiveViewport)
(princ)
)
@devitg wrote:
hi @Kent1Cooper , I test Overkill at this dwg , It did not kill the dup points at the Pline at the block reference.
No, but once inside the Block definition, it should do it in lieu of whatever routine you are using. And it will also get rid of any possible duplicate entire Polyline(s).
Hello Kent,
I've tested the "Overkill" command and it does remove the 0-length segments, but it also leaves the polyline in separate pieces (divided where the 0-length segments were). That's ok though, I've included the "Join" command to rejoin the sections.
Thanks again for letting me know about the Overkill command.
@mgorecki wrote:
... the "Overkill" command ... does remove the 0-length segments, but it also leaves the polyline in separate pieces (divided where the 0-length segments were). ....
If you're doing that within BEDIT or REFEDIT, I wonder whether there's something peculiar about that nested context. It didn't do that for me in a "top-level" Polyline, which I had tried it on before suggesting it. I did not even have "Do not break polylines" checked in the Overkill Options:
but might it make the difference for you if you check that?
Can't find what you're looking for? Ask the community or share your knowledge.