Quick mirror...

Quick mirror...

rob.aHH2T8
Enthusiast Enthusiast
3,971 Views
31 Replies
Message 1 of 32

Quick mirror...

rob.aHH2T8
Enthusiast
Enthusiast

How can I mirror an object using two lines?  Many commands have variables, but mirror seems to have none.

 

Thanx!

Accepted solutions (2)
3,972 Views
31 Replies
Replies (31)
Message 2 of 32

Ranjit_Singh
Advisor
Advisor

I assume you mean mirroring wrt a line?

(defun c:somefunc  (/ etdata)
 (command "._mirror"
          (ssget)
          ""
          (cdr (assoc 10 (setq etdata (entget (car (entsel "\nSelect reference line: "))))))
          (cdr (assoc 11 etdata))
          "_n"))

mirr@line.gif

 

0 Likes
Message 3 of 32

john.uhden
Mentor
Mentor

AS @Ranjit_Singh indirectly pointed out, the MIRROR command actual takes three (3) inputs:  one selection set and two reference points.  He just didn't waste any time assigning any of them to variables; well, except for the reference line itself.

Wait, there's actually a 4th input... to delete the selected objects, Yes or No.  They can all be considered variables.

 

Oh, and you don't need two lines, just one line with two endpoints.  Actually, you don't need a line at all but just provide two points to define the mirror line.  But picking one line is easier (with Ranjit's help).

John F. Uhden

0 Likes
Message 4 of 32

Kent1Cooper
Consultant
Consultant

@rob.aHH2T8 wrote:

How can I mirror an object using two lines?  ....


I confess to not understanding what you mean by that.  Can you illustrate?

Kent Cooper, AIA
0 Likes
Message 5 of 32

rob.aHH2T8
Enthusiast
Enthusiast

Ranjit's solution only deletes one step... I want a lisp that you only have to click on the 2 vertical lines and it does the rest (so I don't have to draw the extra line)  My thought is it would almost be like using the M2P command but would a little more applicable to this situation.

 

 

20171215_085952.jpg

0 Likes
Message 6 of 32

john.uhden
Mentor
Mentor

It's good that @Kent1Cooper asked.

 

Might it be that you want to mirror the left side of your "house" to the right?

How about if all you have to pick for the mirror line is the horizontal line shown in the right side of the image?

We can have it mirror your wall and roof parallel to that line at its midpoint.  Yes, maybe?

Or maybe you want to pick the two wall lines in the left side of the image and it mirrors the roof (and whatever else) about a midpoint between the two walls?

John F. Uhden

0 Likes
Message 7 of 32

ВeekeeCZ
Consultant
Consultant

Just playin'... one way or another.

 

(defun c:MV2 ( / *error* ass osm ss p1 p2)
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if osm (setvar 'OSMODE osm))
    (if ass (setenv "AutoSnapSize" ass))
    (princ))
  
  (if (and (ssget "_:L")
           (setq osm (getvar 'OSMODE)
                 ass (getenv "AutoSnapSize"))
           (setvar 'OSMODE 512)
           (setenv "AutoSnapSize" "15")
           (setq p1 (getpoint "\nFirst point: "))
           (setq p2 (getpoint p1 "\nSecond point: "))
           (setvar 'OSMODE 0)
           )
    (command "_.MIRROR" "_P" "" "_m2p" p1 p2 "@0,1" "_N"))
  (*error* "end")
  )


(defun c:MV3 ( / en1 en2)
  (if (and (ssget "_:L")
           (setq en1 (car (entsel "\nFirst line: ")))
           (setq en2 (car (entsel "\nSecond line: ")))
           )
    (command "_.MIRROR" "_P" ""
             "_m2p"
             "_none" (trans (cdr (assoc 10 (entget en1))) 0 1)
             "_none" (trans (cdr (assoc 10 (entget en2))) 0 1)
             "@0,1" "_N"))
  (princ)
  )
Message 8 of 32

Ranjit_Singh
Advisor
Advisor

@rob.aHH2T8 wrote:

Ranjit's solution only deletes one step... I want a lisp that you only have to click on the 2 vertical lines and it does the rest (so I don't have to draw the extra line)  My thought is it would almost be like using the M2P command but would a little more applicable to this situation.

 


I have the same questions as @john.uhden. It is not clear what your goal is. You are saying pick 2 vertical lines? Your problem picture shows 2 vertical lines but the solution picture shows the sloping line mirrored? May be add some annotation to your picture and explain better what you want to click and what you want to mirror.
0 Likes
Message 9 of 32

john.uhden
Mentor
Mentor

... or another. Smiley Wink

 

I'm surprised that your AutoSnapSize symbol didn't get bleeped, but **** is still a valid symbol anyway.

 

I liked your "@0,1" rather than (polar this that (+ etc.)) or (mapcar '+ ) which I would have verbosely done.

John F. Uhden

0 Likes
Message 10 of 32

rob.aHH2T8
Enthusiast
Enthusiast

The pic shows a roof pitch (angled line) and two wall lines (vertical).  The goal is to mirror the roof pitch between the two vertical lines to complete the gable (simplified) by only clicking on the two vertical lines (the assumption is that a lisp can find the midpoint of two vertical lines without having to draw a line between)   The over all goal is to mirror an object without having to draw any extra lines.

 

Thanx!

0 Likes
Message 11 of 32

Ranjit_Singh
Advisor
Advisor
Accepted solution

@rob.aHH2T8 wrote:

The pic shows a roof pitch (angled line) and two wall lines (vertical).  The goal is to mirror the roof pitch between the two vertical lines to complete the gable (simplified) by only clicking on the two vertical lines (the assumption is that a lisp can find the midpoint of two vertical lines without having to draw a line between)   The over all goal is to mirror an object without having to draw any extra lines.

 

Thanx!



OK. Try below. You will still need to select the roof pitch after selecting the 2 lines.

(defun c:somefunc  (/ ent1 ent2 ep1 ep2 pt1 pt2 sp1 sp2 tmp)
 (setq ent1 (car (entsel "\nSelect first line: "))
       ent2 (car (entsel " \nselect second line: "))
       sp1  (vlax-curve-getstartpoint ent1)
       ep1  (vlax-curve-getendpoint ent1)
       sp2  (vlax-curve-getstartpoint ent2)
       ep2  (vlax-curve-getendpoint ent2))
 (if (> (distance sp1 sp2) (distance sp1 ep2))
  (setq tmp sp2
        sp2 ep2
        ep2 tmp))
 (setq pt1 (mapcar '/ (mapcar '+ sp1 sp2) '(2 2))
       pt2 (mapcar '/ (mapcar '+ ep1 ep2) '(2 2)))
 (command "._mirror" (ssget) "" pt1 pt2 "_n"))

 mirr_with_2_lines.gif

Message 12 of 32

rob.aHH2T8
Enthusiast
Enthusiast

Booyaah!  Perfect!  Thanks for allowing it to be "objects" at the end!

0 Likes
Message 13 of 32

john.uhden
Mentor
Mentor

@Ranjit_Singh is pretty cool, eh?

 

God bless him.

John F. Uhden

0 Likes
Message 14 of 32

Ranjit_Singh
Advisor
Advisor

@john.uhden wrote:

@Ranjit_Singh is pretty cool, eh?

 

God bless him.


Smiley HappyGod bless you too @john.uhden and all the rest of the community members.

 

0 Likes
Message 15 of 32

SEANT61
Advisor
Advisor

Ranjit, your screen capture shows the use of lines at arbitrary lengths.  If that is the case then a bisector is not guaranteed by the use of the average of endpoints.  See attached.  The routine does not create a mirror with the same angle as the first.


************************************************************
May your cursor always snap to the location intended.
0 Likes
Message 16 of 32

john.uhden
Mentor
Mentor

It is usually impossible to find fault with your code, but in this case I am wondering.

It seems to assume that the two wall lines are either vertical or have an isosceles relationship, resulting in a mirror line that is vertical.

Were the two lines parallel and not vertical, the mirror line would not be vertical, and probably not be what the OP is looking for.

I am thinking that the OP intends to deal with walls that are both vertical and therfor parallel, which would make your code work.  I just don't want the lurkers to think that any two walls have a unique vertical mirror line.

 

BTW, this reveals another opportunity to use @_gile's swap method.

Instead of 

(setq tmp sp2
        sp2 ep2
        ep2 tmp))
you can...
(mapcar 'set '(sp2 ep2)(list ep2 sp2))

John F. Uhden

0 Likes
Message 17 of 32

Kent1Cooper
Consultant
Consultant

@rob.aHH2T8 wrote:

....  The goal is to mirror the roof pitch between the two vertical lines ....


Given that, and if the two vertical things are always Line entities specifically, you're covered.  If they might ever be something else  [e.g. any straight nested object in a Block, a Polyline line segment, a Ray, an Xline, etc.], code could be stolen from my Bisector.lsp routine's BI command, available here, and modified for mid-command calculation of an axis rather than to draw  an Xline.  If the concern expressed in Post 15 is a possible issue, what BI finds, when the two objects [or sub-objects] are not parallel, is the angle bisector  between them.

Kent Cooper, AIA
0 Likes
Message 18 of 32

john.uhden
Mentor
Mentor

I missed it before.  The OP did say two vertical lines, in which case Ranjit's code is fine, even if it could be done in several other ways.

Bisecting some odd angles may be good for Gehry, but probably not for a standard gable.  Nevermind.  Gehry wouldn't bisect anything.

John F. Uhden

0 Likes
Message 19 of 32

SEANT61
Advisor
Advisor

Kent and John, what are your opinions:  Is the “concern expressed in Post 15” an issue?  The screen cast implies functionality that may be beyond the scope of the OP, but the implication exists nonetheless.  Future readers may have slightly different requirements.


What responsibilities do we have regarding the content of our responses?


************************************************************
May your cursor always snap to the location intended.
0 Likes
Message 20 of 32

john.uhden
Mentor
Mentor

My opinion is that we need to read the original posts better.

Were we to have recognized the "two vertical lines" then the idea of a bisector is minimized.

Two vertical lines are by definition parallel, so all that was needed was two midpoints between them, one being the average X of either start or end points and another "@0,1" or "@0,10" or another.  Then again one could argue that the function should also work for bird houses with nonvertical walls, but that was not in the original request.

 

I'm not sure what you mean by the extents of responsibilities.  Certainly if we provide faulty/erroneous solutions, then shame on us, but usually someone else here points out the error(s) and all ends up well, with all observers having learned by mistake.  We should all probably read the forum rules as to liability of participants.  In my mind it is the obligation of the OP and any lurkers to test the code in the responses before applyling them to a real life project.  As to other content we should all strive to be polite and avoid belittleing anyone except an obviously obnoxoius **** crank, or simply in jest.

John F. Uhden

0 Likes