MarcoW Posted December 23, 2009 Posted December 23, 2009 I want to mirror a block, yet slightly different then usual. First part should be like the way mirror usual goes: 1. select objects 2. select line to mirror to -> now the "new block" appears (the new, mirrored version) 3. ask for delete originals -> no retain. Then, the command should not STOP but do a little extra: 4. Mirror the "new block" again 5. Mirroring line: point 1 is its insertion point 6. Mirroring line: point 2 is its insertion point + 180 rotation. 7. ask for delete original -> Yes delete. In this way one could mirror a block but the result is a block that apears as it should, not mirrored. I only come this far, but it doesn't work. Plus: how would I set it up so it does the trich for multiple blocks... (like the original mirror function)? Lacking knowledge -> struggle with this. (defun C:mm (/) (setq orth1 (getvar "orthomode") ; current orthomode osm1 (getvar "osmode") ; current osnapmode ss (ssadd) ; create empty selection set ) (setvar "orthomode" 1) ; turn on ortho (setvar "osmode" 1) ; turn on osnap (setq mirpt1 (getpoint "First mirror point") mirpt2 (getpoint mirpt1 "Second mirror point") ) (setq ent (ssget)) ; put object(s) in ent (setvar "osmode" 0) ; turn osmode off (command "mirror" ent "" pt1 pt2 "n") ; mirror the object(s) and retain original (ssadd (entlast) ss) ; add the last created entity in the selection set ss (setq inspt1 (cdr (assoc 10 ss)) ; Insertion Point of the last created entity rot (cdr (assoc 50 ss)) ; rotation of the last created entity inspt2 (polar inspt (+ rot pi) 1000) ; create second point in line with inspt1 ) (command "mirror" ss "" inspt1 inspt2 "y") ; mirror the object(s) and delete the original (setvar "orthomode" orth1) (setvar "osmode" osm1) ) Quote
alanjt Posted December 23, 2009 Posted December 23, 2009 Once you've mirrored the first, couldn't you just copy from then on? Quote
Lee Mac Posted December 23, 2009 Posted December 23, 2009 Marco, Your method is only valid for blocks with a central base point, see below: (defun c:mm2 (/ i ss pt1 pt2 tmp ent p1 p2) (vl-load-com) (if (and (setq i -1 ss (ssget "_:L" '((0 . "INSERT")))) (setq pt1 (getpoint "\nSelect First Point: ")) (setq pt2 (getpoint pt1 "\nSelect Second Point: "))) (progn (setq tmp (entmakex (list (cons 0 "LINE") (cons 10 pt1) (cons 11 pt2)))) (while (setq ent (ssname ss (setq i (1+ i)))) (setq p2 (vlax-curve-getClosestPointto tmp (setq p1 (cdr (assoc 10 (entget ent)))) t)) (vla-move (vla-copy (vlax-ename->vla-object ent)) (vlax-3D-point p1) (vlax-3D-point (polar p1 (angle p1 p2) (* 2. (distance p1 p2)))))) (entdel tmp))) (princ)) (defun c:mm3 (/ i ss pt1 pt2 ent ss obj Mi Ma cen tmp) (vl-load-com) (if (and (setq i -1 ss (ssget "_:L" '((0 . "INSERT")))) (setq pt1 (getpoint "\nSelect First Point: ")) (setq pt2 (getpoint pt1 "\nSelect Second Point: "))) (while (setq ent (ssname ss (setq i (1+ i)))) (setq cen (polar (car ptlst) (apply (function angle) ptLst) (/ (apply (function distance) ptlst) 2.)) tmp (vla-mirror (vlax-ename->vla-object ent) (vlax-3D-point pt1) (vlax-3D-point pt2))) (vla-getBoundingBox tmp 'Mi 'Ma) (setq ptlst (mapcar (function vlax-safearray->list) (list Mi Ma))) (vla-mirror tmp (vlax-3D-point cen) (vlax-3D-point (polar cen (/ pi 2.) 1.))) (vla-delete tmp))) (princ)) Quote
MarcoW Posted December 23, 2009 Author Posted December 23, 2009 Guys, I'll be taking a holliday now until 04 january. I am shure that I will check the code before that date! Thanks for reply and I will test the codes home this weekend. Have a great Christmas and a happy new year !! Cheers, Marco. Quote
ReMark Posted December 23, 2009 Posted December 23, 2009 And this would be useful because...? I guess this is the part that fogs my brain: "In this way one could mirror a block but the result is a block that apears as it should, not mirrored." Isn't a block that appears as it should (like the original block) just a copy of itself? Quote
alanjt Posted December 23, 2009 Posted December 23, 2009 And this would be useful because...? LoL Precisely what I was trying to figure out. Quote
ReMark Posted December 23, 2009 Posted December 23, 2009 I think I know what the OP is trying to do. He's preparing for the day AutoDesk announces there will no longer be a Copy command included in AutoCAD. Quote
Lee Mac Posted December 23, 2009 Posted December 23, 2009 I thought the idea was the get the positional effect of mirroring, but without the visual difference (copying, as you say - which is what one part of my code above is doing). Quote
ReMark Posted December 23, 2009 Posted December 23, 2009 Positional effect of mirroring? Isn't that what the copy/rotate command is for? Quote
Lee Mac Posted December 23, 2009 Posted December 23, 2009 Positional effect of mirroring? Isn't that what the copy/rotate command is for? .... Yup Quote
MarcoW Posted December 23, 2009 Author Posted December 23, 2009 Hello again, I had to try! Lee, this is what happened after selecting 4 blocks: Command: mm3 Select objects: 1 found Select objects: 1 found, 2 total Select objects: 1 found, 3 total Select objects: 1 found, 4 total Select objects: Select First Point: Select Second Point: ; error: too few arguments So that does not seem to work... Maybe I can fix it myself but if there is one thing I have learned lately is that I am a bit of a rookie. The answer to the question... I can imagine why anyone would ask what purpose I have for such routine. As Lee said: I thought the idea was the get the positional effect of mirroring, but without the visual difference (copying, as you say - which is what one part of my code above is doing). Yes that is what I want to do. In my daily work we install plumbing / electrics etc. Mostly in houses. In most projects there are several types of houses, like a small one, big one, one in the middle, house on the corner. And the mirrored ones. If I mirror the blocks from the normal house to the mirrored one then all my block are mirrored themselfs. To follow standards like NEN / ISO etc. one must mirror them back. Therefore I need it. I think I know what the OP is trying to do. He's preparing for the day AutoDesk announces there will no longer be a Copy command included in AutoCAD. YOur right, but do not tell Quote
Lee Mac Posted December 23, 2009 Posted December 23, 2009 Apologies, I messed with the order of the code, and messed up in my haste (defun c:mm3 (/ i ss pt1 pt2 ent ss obj Mi Ma cen tmp) (vl-load-com) (if (and (setq i -1 ss (ssget "_:L" '((0 . "INSERT")))) (setq pt1 (getpoint "\nSelect First Point: ")) (setq pt2 (getpoint pt1 "\nSelect Second Point: "))) (while (setq ent (ssname ss (setq i (1+ i)))) (setq tmp (vla-mirror (vlax-ename->vla-object ent) (vlax-3D-point pt1) (vlax-3D-point pt2))) (vla-getBoundingBox tmp 'Mi 'Ma) (setq ptlst (mapcar (function vlax-safearray->list) (list Mi Ma)) cen (polar (car ptlst) (apply (function angle) ptLst) (/ (apply (function distance) ptlst) 2.))) (vla-mirror tmp (vlax-3D-point cen) (vlax-3D-point (polar cen (/ pi 2.) 1.))) (vla-delete tmp))) (princ)) Quote
MarcoW Posted December 23, 2009 Author Posted December 23, 2009 Lee, see these images, can you follow me? I mean, the code is great but not 100%. Quote
fixo Posted December 23, 2009 Posted December 23, 2009 Why mirror? See code ;; mirror_blocks.lsp (defun C:MIRB (/) (prompt "\n\t\t>>>\tSelect mirror line \t>>>") (if (setq lset (ssget ":S" '((0 . "LINE")))) (progn (setq ln (ssname lset 0) elist (entget ln) sp (cdr (assoc 10 elist)) ep (cdr (assoc 11 elist)) ) (prompt "\n\t\t>>>\tSelect blocks to mirror \t>>>") (setq bset (ssget (list (cons 0 "INSERT")))) (while (setq en (ssname bset 0)) (setq elist (entget en) ipt (cdr (assoc 10 elist)) lnpt (vlax-curve-getclosestpointto ln ipt) ang (angle ipt lnpt) dist (distance ipt lnpt) movept (polar lnpt ang dist) ) (command "._copy" en "" "_non" ipt "_non" movept) (ssdel en bset) ) ) ) (princ) ) (prompt "\n\t\t>>>\tType MIRB or mirb to run...\t<<<") (prin1) ~'J'~ Quote
Lee Mac Posted December 23, 2009 Posted December 23, 2009 Yeah, that was my approach in MM2 here Quote
fixo Posted December 23, 2009 Posted December 23, 2009 Yeah, that was my approach in MM2 here Didn't see your code - it only logically ~'J'~ Quote
MarcoW Posted December 25, 2009 Author Posted December 25, 2009 (My wife spilled large Coca Cola on my keybord space bar and N are sticky - forgive the spellig) Hi guys, I have tested all codes but there is one problem. From the code Fixo supplied: I like the way it works. Selecting the mirror line first and then the blocks. THen it mirrors like it should but not all off them. See image. Please fix-o. :wink: Could themirror line be a xref too? What about text? It does not do that, is that possible? WIll buy nw keybord first. (Those white thinngies are the insertion points) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.