Hi, I have this DWG file (attached). It contains dynamic block with an alignment parameter. Is there a wat to automatically align al of them?
The original is on the left of the drawing (A) and the result I am asking is on the right (B)
Thank you very much in advance.
Solved! Go to Solution.
Solved by CADaSchtroumpf. Go to Solution.
Solved by CADaSchtroumpf. Go to Solution.
Hi,
Try with this (copy/paste the code directly in command line)
((lambda ( / js n en js_pl en_pl dxf_ent pt_ins deriv alpha)
(defun update_block (block_record ang pt / s_e dxf_e)
(if (/= (getvar "ATTMODE") 1) (setvar "ATTMODE" 1))
(setq s_e block_record)
(while (/= (cdr (assoc 0 (entget (setq s_e (entnext s_e))))) "SEQEND")
(setq dxf_e (entget s_e))
(if (eq (cdr (assoc 0 dxf_e)) "ATTRIB")
(progn
(entmod (setq dxf_e (subst (cons 50 ang) (assoc 50 dxf_e) dxf_e)))
(entmod (setq dxf_e (subst (cons 10 (polar pt (+ (angle pt (cdr (assoc 10 dxf_e))) ang) (distance pt (cdr (assoc 10 dxf_e))))) (assoc 10 dxf_e) dxf_e)))
)
)
)
(entupd block_record)
)
(princ "\nSelect the blocks to align")
(setq js (ssget '((0 . "INSERT") (67 . 0) (8 . "חשמל") (66 . 1) (2 . "`*U*"))))
(cond
(js
(repeat (setq n (sslength js))
(setq en (ssname js (setq n (1- n))))
(if (/= (getpropertyvalue en "BlockTableRecord/Name") "GOOD")
(ssdel en js)
)
)
(cond
(js
(princ "\nSelect the polyline")
(while (null (setq js_pl (ssget "_+.:E:S" '((0 . "LWPOLYLINE") (67 . 0) (8 . "חשמל")))))
(princ "\nOject isn't valide")
)
(setq en_pl (ssname js_pl 0))
(repeat (setq n (sslength js))
(setq
en (ssname js (setq n (1- n)))
dxf_ent (entget en)
pt_ins (cdr (assoc 10 dxf_ent))
deriv (vlax-curve-getfirstderiv en_pl (vlax-curve-getparamatpoint en_pl (vlax-curve-getClosestPointTo en_pl pt_ins)))
alpha (- (atan (cadr deriv) (car deriv)) (angle '(0 0 0) (getvar "UCSXDIR")))
)
(entmod (subst (cons 50 alpha) (assoc 50 dxf_ent) dxf_ent))
(update_block en alpha pt_ins)
)
)
)
)
)
(prin1)
))
I saved the file in DOS-862 codepage (Hebrew) under the name: yu85_info.lsp
Drag this file from windows explorer into the autocad graphics window. The YU85_INFO command must be available.
Otherwise check the characters "חשמל" (layer name) under your system in the delivered lisp file.
If you have (8 . "????") change to (8 . "חשמל"), there are 2 occurrences in the file.
For my part I can not test this lisp because autocad no longer understands it (it understands it in ANSI)
Hi @CADaSchtroumpf , You have helped me a lot. If it is ok I have another question.
I've changed the layer name in the DWG attached ("dwg1") to English [ELEC]. I've changed your lisp I have attached ("aba") in ANSI. But is there a way to make it variable so it will not fit only to one layer. For example I've added a copy of the block and the polyline to another layer - "TEST". If I try to make this command on this layer it does not work unless I change the LISP to "TEST" instead of "ELEC".
I mean that it will do this to any block I will pick no matter in which layer it is.
Thank you very very much sir
So I introduced an additional step: you have to make a unique selection of a dynamic block.
This allows you to create a specific selection filter with the name of the block, its insertion layer, etc.
So it should also work with another dynamic block other than 'GOOD'
On the other hand, the alignment polyline must also be on the same layer as the insertion of the blocks (this can be deleted)
I also fixed a bug on the positioning of attributes
THIS IS JUST GREAT!
You have saved me so much time. I appreciate it so much.
Thank you sir.
Hi, @CADaSchtroumpf sorry to disturb you again. It seems that when the block is aligned to the polyline it turns upside down. I don't know how to fix it.
I will appreciate it very much if you will have time to look at it.
I attached the LISP and a DWG file that I used with your great LISP.
Thank you very much sir
Here is what I can do to improve the reading, however the alignment will not be perfect if there is a flip.
This is because your block is right justified.
It would be necessary to make a justified block in the center so that it is a little less shocking ...
Before line 67 : (entmod (subst (cons 50 alpha) (assoc 50 dxf_ent) dxf_ent))
Insert this two lines
(if (< alpha 0.0) (setq alpha (+ (* 2 pi) alpha)))
(if (and (> alpha (* pi 0.5)) (< alpha (* pi 1.5))) (setq alpha (rem (+ alpha pi) (* 2 pi))))
Hello all,
Is anybody able to help me modify this lisp so that it works for 3D Polylines?
Thanks CADaSchtroumpf for an awesome start.
Here's a copy of what I am using currently however it only seems to work for 2D Polylines and the models I work in are 3D
Since this is an old thread thought I would reply to you and see if you're able to help with the above.
Thank you in advance