Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LISP TO re-insert all blocks or fix mirror text

19 REPLIES 19
Reply
Message 1 of 20
jtm2020hyo
1787 Views, 19 Replies

LISP TO re-insert all blocks or fix mirror text

I'm not sure what happens with the attached blocks, check the image, all of them are the same block, some of them has mirror text,  I already tried everything, attsync, purge, resetblock, scale re-scale, etc.
I do not what happen, but the unique solution that found was to re-insert all blocks.

so I need a lisp for that.


 

imagen.png

19 REPLIES 19
Message 2 of 20
cadffm
in reply to: jtm2020hyo

When these block references were created, the UCS was rotated 180 ° around the Y-axis

- Sebastian -
Message 3 of 20
jtm2020hyo
in reply to: cadffm

How can I rotate those blocks to 0° again?

Message 4 of 20
marko_ribar
in reply to: jtm2020hyo

Can we have sample DWG...

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 5 of 20
jtm2020hyo
in reply to: marko_ribar

re-attached my dwg with the blocks that I need to re-insert with the name:

bug TEXT BLOCK EXPLODED.dwg

 

attached my dwg from where I created my previous drawing, selecting all blocks and exploding, then re-scaling to x1 y1 z1 , then the blocks appear as if they are mirrored, name of attached dwg:

bug ORIGEN OF BLOCKS.dwg

if you mean that I need to sample for the lisp, I just need to re-insert the same blocks in the same point, without mirrored text, with fixed ucs.

I think a sample might be export to csv, then import the csv for re-insert the blocks. attached below with name:

sample csv reinsert.csv

Message 6 of 20
dlanorh
in reply to: jtm2020hyo

I can't open any of your drawings as they are in a later version to mine (2012). Are you sure none of these mirrored blocks have negative scale factors?

 

I am not one of the robots you're looking for

Message 7 of 20
jtm2020hyo
in reply to: dlanorh

re-attached dwg samples in version AutoCAD 2010.

 

... and yes, none of the blocks were scaled to negative factors, that is why I think maybe a bug.

Message 8 of 20
dlanorh
in reply to: jtm2020hyo

My tests show that the mirrored blocks have a -1.0 value for EffectiveXScaleFactor and XScaleFactor so you must assume that the bug is in the program that inserts the blocks.

I am not one of the robots you're looking for

Message 9 of 20
hak_vz
in reply to: jtm2020hyo

No lisp is needed to fix this.

In some part of your drawing process some blocks were created by using MIRROR command. That is why they have scaleX and (or) scaleY set to -1- To fix this select all blocks and set those values to 1. In blocks there  is also a text oriented upside down.

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 10 of 20
jtm2020hyo
in reply to: hak_vz


@hak_vz wrote:

No lisp is needed to fix this.

In some part of your drawing process some blocks were created by using MIRROR command. That is why they have scaleX and (or) scaleY set to -1- To fix this select all blocks and set those values to 1. In blocks there  is also a text oriented upside down.

 

 


 

I already tried that, all those are the same blocks, are already scaled to "+1", I already tried to use BEDIT, REFEDIT, MIRRORTEXT, etc. then, what more should I do?

 

Message 11 of 20
dlanorh
in reply to: jtm2020hyo

This is probably overkill but run this:

 

(defun rh:gbbc (obj / ll ur lst c_pt)
  (if (and obj (= (type obj) 'ENAME))  (setq obj (vlax-ename->vla-object obj)))
  (cond (obj
          (vlax-invoke-method obj 'getboundingbox 'll 'ur)
          (setq lst (mapcar 'vlax-safearray->list (list ll ur))
                c_pt (mapcar '(lambda (x y) (/ (+ x y) 2.0)) (car lst) (cadr lst))
          );end_setq
        )
  );end_cond
  c_pt
);end_defun

(defun rh:mirr (obj pt lst / n_obj) (setq n_obj (vlax-invoke obj 'mirror pt (mapcar '+ pt lst))) (vla-delete obj) n_obj)

(defun c:CBM ( / ss cnt obj i_pt c_pt x y z)
  (setq ss (ssget "_X" '((0 . "INSERT"))))
  (cond (ss
          (repeat (setq cnt (sslength ss))
            (setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt))))
                  i_pt (vlax-get obj 'insertionpoint)
                  c_pt (rh:gbbc obj)
                  x (vlax-get obj 'XScaleFactor)
                  y (vlax-get obj 'YScaleFactor)
                  z (vlax-get obj 'ZScaleFactor)
            )
            (cond ( (equal i_pt c_pt 0.1)
                    (mapcar '(lambda (x) (if (minusp (vlax-get obj x)) (vlax-put obj x (abs (vlax-get obj x)))))
                       '(XScaleFactor YScaleFactor ZScaleFactor)
                    )
                  )
                  (
                    (if (minusp x) (setq obj (rh:mirr obj c_pt '(0.0 1.0 0.0))))
                    (if (minusp y) (setq obj (rh:mirr obj c_pt '(1.0 0.0 0.0))))
                    (if (minusp z) (setq obj (rh:mirr obj c_pt '(0.0 0.0 1.0))))
                  )
            )
          );end_repeat
        )
  );end_cond
)

As @hak_vz  mentioned you can also select all the mirrored blocks and type properties and the command line

You will see that the x has a -1 click in this box and set to 1

I am not one of the robots you're looking for

Message 12 of 20
hak_vz
in reply to: jtm2020hyo

When I open your drawing all blocks have wrong orientation. Just by opening properties window, selecting all block and setting values scaleX and Scale Y to 1 puts them in good orientation, at least text TD.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 13 of 20
jtm2020hyo
in reply to: hak_vz

imagen.png

 

imagen.png

 

I already did again, but nothing change.

Message 14 of 20
jtm2020hyo
in reply to: dlanorh

 

imagen.png

block and text still mirrored after using CBM (your lisp)

Message 15 of 20
hak_vz
in reply to: jtm2020hyo

I have found problem. Don't know the reason why this happen but.

All wrong blocks appear flipped but I didn't find that flipping has been used in block edit.

Here is what has to be done. 

For the block

Change extrusion direction from (210 0 0 -1) to (210  0 0 1)

Change insertion point from (10 -x y 0) to (10 x 0)

 

Here is a non tested code. It's time to go to bed.

 

(defun c:repblk ( / ent x y z )
(setq e (car (entsel "\n Select block >")) ent (entget e))
(mapcar 'set '(x y z) (cdr (assoc 10 ent)))
(setq ent (subst (cons 10 (list (* -1 x) y z)) (assoc 10 ent) ent))
(entmod ent)
(setq ent (subst (cons 210 (list 0 0 1)) (assoc 210 ent) ent))
(entmod ent)
(setq e (entnext e) ent (entget e))
(mapcar 'set '(x y z) (cdr (assoc 10 ent)))
(setq ent (subst (cons 10 (list (* -1 x) y z)) (assoc 10 ent) ent))
(entmod ent)
(setq ent (subst (cons 210 (list 0 0 1)) (assoc 210 ent) ent))
(entmod ent)
(princ)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 16 of 20
dlanorh
in reply to: jtm2020hyo

Worked for my on your supplied drawing.

I am not one of the robots you're looking for

Message 17 of 20
jtm2020hyo
in reply to: hak_vz

thanks for answer.
it is a good start.

imagen.png

imagen.png

 

but when the block has rotation does not work correctly.

 

imagen.png

 

imagen.png

 

the orientation for text was mirrored to the square block.
it is there any way to select all or some blocks?

Message 18 of 20
jtm2020hyo
in reply to: dlanorh


@dlanorh wrote:

Worked for my on your supplied drawing.


can you share your method?

Message 19 of 20
dlanorh
in reply to: jtm2020hyo

I ran the posted lisp on the origin dwg, and then no problems appeared as the blocks were exploded.

 

Your problem may be related to the alignment parameter of the innermost block. This is configured 180 degrees from the x normal, and is away from the block insertion point. This block is then scaled up and nested in another block, which in turn is nested inside another block, and so on, and therein lies the problem.

I am not one of the robots you're looking for

Message 20 of 20
jtm2020hyo
in reply to: dlanorh

thanks for the answer.

I was testing in the "Origen dwg". applying your lisp individually fix the position, then I can explode with problems.

but I need to keep the position and rotation (without the mirrored bug).

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost