Block Reinsert

Block Reinsert

Anonymous
Not applicable
2,073 Views
12 Replies
Message 1 of 13

Block Reinsert

Anonymous
Not applicable

Hi everyone. I have that problem, I have a file with many blocks that for some reason cant replace effectively ( elev, extrude, z axis, extrude direction and other problems...)

 

I think that the only way to solve this i reinserting automatically the blocks (no replacing or redefining couse like i tell the blocks are damaged)

Then to reinsert the blocks i need some data (3) Position, rotation and mirror of the blocks inserted in the drawing to reinsert the new block

and then deleted the olds.

 

I search in the forum but i dont find any like this.

 

Any help Please??

 

thanks in advanced

Claudio

Accepted solutions (1)
2,074 Views
12 Replies
Replies (12)
Message 2 of 13

SeeMSixty7
Advisor
Advisor
I'm not sure if you are interested in Learning Lisp or just want a routine. It sounds like you just want a routine but you are asking very specifically for data to insert them again.

So for the learning part.
First you can get a selection set of your block inserts.
(setq myss (ssget "X" '((0 . "INSERT"))))
next step is to figure out how many blocks you have
(setq mysslen (sslength myss))
Next we loop through all of the block inserts. I personally like using a while loop for this
(setq mycnt 0) ; Sets my start index
(while (< mycnt mylen)
(setq myent (ssname myss mycnt)
mydata (entget myent)
myins (cdr (assoc 10 mydata)) ; This is the insert point of the block it contains the WCS 3D point
myXscale (cdr (assoc 41 mydata)) ; This is the XScale factor
myYscale (cdr (assoc 42 mydata)) ; This is the YScale Factor
myZScale (cdr (assoc 43 mydata)) ; This is the ZScale Factor
myRot (cdr (assoc 50 mydata)); This is the rotation
myblkname (cdr (assoc 2 mydata)) ; This is the block name
mycnt (1+ mycnt) ; bump the index counter
)
;From that information you have a crude set to do your block inserts
(entdel myent) ; Delete the old entity
(setq attreqval (getvar "ATTREQ")); Store the state of attreq
(setvar "ATTREQ" 0) ; Turn off attribute prompts
(command "insert" myblkname "X" myxscale "Y" myyscale "Z" myzscale myins myrot)
(setvar "ATTREQ" attreqval) ; Set the ATTREQ variable back to the original value ); Close the while loop

A few things to note. This is a crude start to a function or command. You will need to wrap a defun around this and define your function name.
There are many other aspects needed to complete this
Will this handle blocks with attributes?
What about maintaining existing attribute values, settings
Will this handle blocks inserted on other Coordinate systems
Error trapping
What about redefining the actual block definition from an external file location
Original Layer insertion
Dynamic blocks and their settings?

As you can see there are many factors to take in consideration, I'm sure I have even left some out.

Good luck
Message 3 of 13

dbroad
Mentor
Mentor

I think purging and programming may be the wrong solution for you.  You have some good ways to access external content these days.

(designcenter and palettes are ones I use).  Even the insert dialog will offer to redefine if you browse to an external file. Redefining preserves the position, rotation, and scaling information without programming. The design center allows a right drag. Palettes offer a right click redefine.

 

Get the content from a location that is correct and redefine in the drawings it is not correct.  If you put all the good blocks into a single drawing, the design center can create a new tool palette for you.  From there it's just right click to redefine.

 

Extrusion direction probably results only from using another ucs to place the block.  It doesn't necessarily make the block broken.  Scanning the drawing to modify the good blocks to correct for normal vector and mirror imaged scale factors wouldn't require redefining the blocks.

 

Architect, Registered NC, VA, SC, & GA.
Message 4 of 13

Anonymous
Not applicable

Hi Dbroad, ans first thanks by the answer.

 

I try everything with this blocks without a positive result.

 

i attach the file, it has 3 blocks similars and one different.

If you can, try "blockreplace" and any other ways you like to replace the 3 blocks with the different

and you will see that 2 blocks will have empty polilines and hatch, meanwhile the other block to replace works fine.

The 2 blocks problems has a "Extrusion direction relative to UCS" and the other no.

 

Beleve me, i try everything with no luck. i think the only way to solve this is re inserting the blocks.

 

if you can help me with this, i sure i will not programig anything...lol

 

But really i dont know the solution.

 

thanks a lot and regards.

Claudio 

0 Likes
Message 5 of 13

Anonymous
Not applicable

Hi  SeemSixty7, and thanks for the replay.

 

First of all, i need the routine but i want to lern too, and your post is very useful for both

The blocks that i want to replace are simple blocks, no attrib, no dynamic, etc...are really very simple.

The only thing that need too is how to know if the block are mirrored or not.

if you can helpme, myt thanks for you.

 

Thanks and regards

 

Claudio

0 Likes
Message 6 of 13

SeeMSixty7
Advisor
Advisor
It looks like your blocks have been created by a binded xref. You can do block replace all day long and it will not affect the blocks with appended names form the original xrefs. Basically you have 3 different block names:
doblebacha-p -- This looks to be the actual Block you want
MIL AIRES E3 Planta Tipo$0$doble bacha-p -- This is a bad one
MIL AIRES E3 Planta Tipo$0$doblebacha-p -- and another bad one
The below routine replaces all blocks with the correct one.
CAUTION: THIS REPLACES ALL BLOCKS WITH THE CORRECT ONE ABOVE. DO NOT DO THIS IN A DRAWING WITH OTHER BLOCKS. THIS IS FOR TESTING!!!

Give this a try

(defun c:quick()
(setq myss (ssget "X" '((0 . "INSERT"))))
(setq mysslen (sslength myss))
(setq mycnt 0) ; Sets my start index
(while (< mycnt mysslen)
(setq myent (ssname myss mycnt)
mydata (entget myent)
myins (cdr (assoc 10 mydata)) ; This is the insert point of the block it contains the WCS 3D point
insscale (/ 1.0 25.4)
myXscale (* (cdr (assoc 41 mydata)) insscale) ; This is the XScale factor
myYscale (* (cdr (assoc 42 mydata)) insscale) ; This is the YScale Factor
myZScale (* (cdr (assoc 43 mydata)) insscale) ; This is the ZScale Factor
myRot (cdr (assoc 50 mydata)); This is the rotation
myblkname (cdr (assoc 2 mydata)) ; This is the block name
mycnt (1+ mycnt) ; bump the index counter
)
(setq attreqval (getvar "ATTREQ")); Store the state of attreq
(setvar "ATTREQ" 0) ; Turn off attribute prompts
(if (equal (assoc 210 mydata) (cons 210 (list 0.0 0.0 1.0)))
(command "UCS" "")
(progn
(command "UCS" "OB" myent)
(setq myins (list 0.0 0.0 0.0))
)
)
(entdel myent) ; Delete the old entity
(command "insert" "doblebacha-p" "X" myxscale "Y" myyscale "Z" myzscale myins (angtos myrot 0 4))
(setvar "ATTREQ" attreqval) ; Set the ATTREQ variable back to the original value );
)
)
0 Likes
Message 7 of 13

patrick_35
Collaborator
Collaborator

Hi


You created (or insert) a new block in the current drawing and with this lisp, you replace bad blocks with good block

 

@+

0 Likes
Message 8 of 13

dbroad
Mentor
Mentor
Accepted solution

Claudio,

After looking at the drawing I agree with @SeeMSixty7.  These blocks are a result of xbinds or parts of drawings left after xref bind as bind. 

 

Guiding principles:  1) Programs cannot replace good drafters or fix bad drafting decisions.  2)Avoid xbinding.  3)Avoid working in the bottom view.

 

This drawing is a mess and should be redrawn.  The cost of the redraw should be born by the drafter who made the mistakes so that he is stung badly enough that he won't repeat his mistakes.

 

That said, it is possible to use the approach I spoke about.  There is nothing inherently wrong with the block defintions.  You have taken blocks drawn in millimeters and inserted them into an imperial drawing.  I generally try to avoid that approach because it leads to confusion.  I only do this when the drawing has been produced and I need a soft conversion to another country.

 

The problems stem from the insertions, which were poorly done by any measure.  You have one block at the origin and the rest far away.  This can be fixed in this instance for the most part by using:

;;Fixes some problems related to bad normals and scale factors.
;;D. C. Broad, Jr. 10/12/2016
;;Replace test with whatever name is significant to you.
(defun c:test (/ pos xs ys zs)
  (if (ssget '((0 . "insert")))
    (vlax-for n	(vla-get-activeselectionset
		  (vla-get-activedocument (vlax-get-acad-object))
		)
      (setq pos	(vla-get-InsertionPoint n)
	    xs	(vla-get-XScaleFactor n)
	    ys	(vla-get-YScaleFactor n)
	    zs	(vla-get-ZScaleFactor n)
      )
      (vla-put-normal n (vlax-3d-point '(0.0 0.0 1.0)))
      (vla-put-InsertionPoint n pos)
      (vla-put-XScaleFactor n (abs xs))
      (vla-put-YScaleFactor n (abs yS))
      (vla-put-ZScaleFactor n (abs zs))
    )
  )
  (princ)
)

Save the code to a .lsp file in a trusted folder and load it with (load "filenameyouchose"). Then run with the test command or whatever name you changed it to.

Architect, Registered NC, VA, SC, & GA.
Message 9 of 13

Anonymous
Not applicable

Hi  Patrick_35, and thanks by the replay. The routine is very good, but still dont solve my prob.

 

Thanks anyway and regards.

Claudio

 

0 Likes
Message 10 of 13

Anonymous
Not applicable

Hi dbroad, thanks for the replays, and for your work.

Really really thanks. The routine works perfectly and repairs the blocks.

 

The problem about the draw is a mess is not becouse of my, im working in a file that other person send me.

 

I understand the origin of the problem but not all users know about it, and dont think i must teach it...lol

But sometimes, like this, a must be capable to "repair" this messes.

 

Thanks a lot again.

 

Claudio.

0 Likes
Message 11 of 13

dbroad
Mentor
Mentor

Glad to help.  Get with your drafter to help him understand the correct way to use blocks and how to use the plan view command and ucs command.  Training your drafters to draft accurately and to use standards will bring many benefits.

Architect, Registered NC, VA, SC, & GA.
Message 12 of 13

patrick_35
Collaborator
Collaborator

Hi

 

Is that I misunderstood your problem and I had not seen that you had left an example.
The main thing is that you have a solution.

 

@+

Message 13 of 13

jtm2020hyo
Collaborator
Collaborator

I have the same problem and I am looking for the same solution.

Did you find what you were looking for?

0 Likes