Jump to content

Lisp to Mirror a selection with one point


Mohz

Recommended Posts

Can I get a lisp to mirror my selection using one point only , one command vertically & other one for  Horizontally

Link to comment
Share on other sites

Above seams a bit long winded try this, as requested 2 commands vertical and horizontal which in this case is probably the quickest option. Add option into the LISP and the command you want to make quicker becomes slower with more user inputs.

 

Commands hmirror and cmirror.

 

 

(defun c:vmirror ( / MySS Pt1 Pt2)
  (princ "\nSelect Objects: [Vertical Mirror] ")
  (setq MySS (ssget))                                   ;; select objects/ Filter this if you want to limit what is selected
  (setq Pt1 (getpoint "\nSelect Mirror Axis Point: "))  ;; get a point
  (setq Pt2 (mapcar '+ '(0 5 0) Pt1))                   ;; make Pt2 5 more in the Y axis - vertically upwards
  (command "Mirror" MySS "" Pt1 Pt2 Pause)              ;; Mirror commmand. Retain pause at the end to keep "retain objects" option
)

(defun c:hmirror ( / MySS Pt1 Pt2)                      ;; Comments as above
  (princ "\nSelect Objects: [Horizontal Mirror] ")
  (setq MySS (ssget))
  (setq Pt1 (getpoint "\nSelect Mirror Axis Point: "))
  (setq Pt2 (mapcar '+ '(5 0 0) Pt1))
  (command "Mirror" MySS "" Pt1 Pt2 Pause)
)

 

Edited by Steven P
Link to comment
Share on other sites

and a little shorter code... Sunday night and time to sit for 20 minutes. Swap it around for vertical mirror

 

(defun c:hmirror ( / )                      ;; Comments as above
  (command "Mirror" (ssget) "" (getpoint "\nSelect Mirror Axis Point: ") (mapcar '+ '(5 0 0) (getvar 'lastpoint)) Pause)
)

 

Edited by Steven P
  • Like 1
Link to comment
Share on other sites

 

This only assumes the horizontal and vertical lines are drawn in UCS, and not WCS:

(defun c:vmirror nil (OnePointMirror '(00 10 00)))
(defun c:hmirror nil (OnePointMirror '(10 00 00)))
(defun OnePointMirror (dir / ss pt)
    (and
        (setq ss (ssget "_:L"))
        (setq pt (getpoint "\nSpecify base point <exit>: "))
        (command "_mirror" ss "" "_non" pt "_non" (mapcar '+ dir pt) "No")  ;; <--- Change to Yes to delete source object, or \\ to prompt user.
        (while (not (zerop (getvar "cmdactive"))) (command ""))
    )
    (princ)
)

 

And while this may be off the OP, this might be worth looking at as well: Quick Mirror.

Edited by Jonathan Handojo
  • Like 4
Link to comment
Share on other sites

Bonjour,
super zézaiement, je cherche depuis longtemps, merci
Serait-il possible d’avoir une version où l’objet en miroir disparaît ?
et un autre à un angle de 45° ?
Ce serait génial
merci encore, vraiment

Link to comment
Share on other sites

45 degree angle...

In all the codes above there is a list something like this: '(0 5 0), change that so the first 2 numbers are the same: '(5 5 0) and use a negative value to rotate the 45 degree angle line:

examples:

'(5 5 0)

'(5 -5 0)

'(-10 -10 00)

'(-10 10 00)

 

 

 

  • Like 1
Link to comment
Share on other sites

Or if you need it to be something other than 45 degrees:

(polar '(0 0 0) (cvunit <your_angle_in_degrees> "degrees" "radians") 10)

 

  • Like 3
Link to comment
Share on other sites

  • 3 weeks later...
On 2/25/2024 at 10:09 PM, Jonathan Handojo said:

 

Cela suppose uniquement que les lignes horizontales et verticales sont tracées dans le SCU, et non dans le SCG :

(defun c:vmirror nil (OnePointMirror '(00 10 00)))
(defun c:hmirror nil (OnePointMirror '(10 00 00)))
(defun OnePointMirror (dir / ss pt)
    (and
        (setq ss (ssget "_:L"))
        (setq pt (getpoint "\nSpecify base point <exit>: "))
        (command "_mirror" ss "" "_non" pt "_non" (mapcar '+ dir pt) "No")  ;; <--- Change to Yes to delete source object, or \\ to prompt user.
        (while (not (zerop (getvar "cmdactive"))) (command ""))
    )
    (princ)
)

 

Et bien que cela puisse être hors de l’OP, cela pourrait également valoir la peine d’être regardé : Miroir rapide.

everything works perfectly
I would like to ask you something if possible.
I associated lisp with icons,
1 icon for vertical mirror
1 icon for horizontal mirror
1 icon for 45° and -45° mirror
all this with deletion of the original object.
I wanted to do the same and keep the original object, however it does not work, in fact it modifies my first orders
can you help me ?

Link to comment
Share on other sites

Make Yes or no  a variable then move it to the other side of / in the defun line. this means you will need to add a call like the dir variable

 

(defun c:KeepHmirror nil (OnePointMirror '(10 00 00) "No")) ;keep source
(defun c:DeleteHmirror nil (OnePointMirror '(10 00 00) "Yes")) ;delete source
(defun OnePointMirror (dir del / ss pt) ;del is yes or no to delete
    (and
        (setq ss (ssget "_:L"))
        (setq pt (getpoint "\nSpecify base point <exit>: "))
        (command "_mirror" ss "" "_non" pt "_non" (mapcar '+ dir pt) del)  ;; <--- Change to Yes to delete source object, or \\ to prompt user.
        (while (not (zerop (getvar "cmdactive"))) (command ""))
    )
    (princ)
)

 

  • Like 1
Link to comment
Share on other sites

10 hours ago, DELLA MAGGIORA YANN said:

everything works perfectly
I would like to ask you something if possible.
I associated lisp with icons,
1 icon for vertical mirror
1 icon for horizontal mirror
1 icon for 45° and -45° mirror
all this with deletion of the original object.
I wanted to do the same and keep the original object, however it does not work, in fact it modifies my first orders
can you help me ?

 

Creating an icon for a LISP code is possible, but it involves modifying your ribbons through the user interface. For starters, I've made you this ribbon that you can use to display the icons in the ribbon. You can have a look into how to use Partial Customization Files to initialise it into your AutoCAD. However, you need to have this one below loaded, not the above (as the command names have been set to these ones in the CUI). In addition, with enough practice, you may even add more of your own codes to this ribbon if you so desire:

 

(defun c:1pm-h nil (OnePointMirror 0 "No"))
(defun c:1pm-hd nil (OnePointMirror 0 "Yes"))
(defun c:1pm-v nil (OnePointMirror 90 "No"))
(defun c:1pm-vd nil (OnePointMirror 90 "Yes"))
(defun c:1pm-45 nil (OnePointMirror 45 "No"))
(defun c:1pm-45d nil (OnePointMirror 45 "Yes"))
(defun c:1pm--45 nil (OnePointMirror -45 "No"))
(defun c:1pm--45d nil (OnePointMirror -45 "Yes"))

(defun OnePointMirror (ang del / ss pt)
    (and
        (setq ss (ssget "_:L"))
        (setq pt (getpoint "\nSpecify base point <exit>: "))
        (command "_mirror" ss "" "_non" pt "_non" (polar pt (cvunit ang "degrees" "radians") 30.0) del)
        (while (not (zerop (getvar "cmdactive"))) (command ""))
    )
    (princ)
)

 

6 hours ago, mhupp said:

Make Yes or no  a variable then move it to the other side of / in the defun line. this means you will need to add a call like the dir variable

 

(defun c:KeepHmirror nil (OnePointMirror '(10 00 00) "No")) ;keep source
(defun c:DeleteHmirror nil (OnePointMirror '(10 00 00) "Yes")) ;delete source
(defun OnePointMirror (dir del / ss pt) ;del is yes or no to delete
    (and
        (setq ss (ssget "_:L"))
        (setq pt (getpoint "\nSpecify base point <exit>: "))
        (command "_mirror" ss "" "_non" pt "_non" (mapcar '+ dir pt) del)  ;; <--- Change to Yes to delete source object, or \\ to prompt user.
        (while (not (zerop (getvar "cmdactive"))) (command ""))
    )
    (princ)
)

 

 

FYI @mhupp, using macros would've sufficed just as well. Instead of "Yes" and "No", you can use "\\" and create a macro called KeepHmirror and DeleteHmirror in which you fix the inputs "Yes" and "No" into the macro itself.

LISP Codes.cuix

Link to comment
Share on other sites

7 hours ago, Jonathan Handojo said:

 

La création d’une icône pour un code LISP est possible, mais cela implique de modifier vos rubans via l’interface utilisateur. Pour commencer, je vous ai créé ce ruban que vous pouvez utiliser pour afficher les icônes du ruban. Vous pouvez découvrir comment utiliser les fichiers de personnalisation partielle pour l’initialiser dans votre AutoCAD. Cependant, vous devez avoir celui-ci ci-dessous chargé, pas le ci-dessus (car les noms de commande ont été définis sur ceux-ci dans le CUI). De plus, avec suffisamment de pratique, vous pouvez même ajouter d’autres de vos propres codes à ce ruban si vous le souhaitez :

 

(defun c:1pm-h nil (OnePointMirror 0 "No"))
(defun c:1pm-hd nil (OnePointMirror 0 "Yes"))
(defun c:1pm-v nil (OnePointMirror 90 "No"))
(defun c:1pm-vd nil (OnePointMirror 90 "Yes"))
(defun c:1pm-45 nil (OnePointMirror 45 "No"))
(defun c:1pm-45d nil (OnePointMirror 45 "Yes"))
(defun c:1pm--45 nil (OnePointMirror -45 "No"))
(defun c:1pm--45d nil (OnePointMirror -45 "Yes"))

(defun OnePointMirror (ang del / ss pt)
    (and
        (setq ss (ssget "_:L"))
        (setq pt (getpoint "\nSpecify base point <exit>: "))
        (command "_mirror" ss "" "_non" pt "_non" (polar pt (cvunit ang "degrees" "radians") 30.0) del)
        (while (not (zerop (getvar "cmdactive"))) (command ""))
    )
    (princ)
)

 

 

FYI @mhupp, l’utilisation de macros aurait tout aussi bien suffi. Au lieu de « Oui » et « Non », vous pouvez utiliser « \\ » et créer une macro appelée KeepHmirror et DeleteHmirror dans laquelle vous fixez les entrées « Oui » et « Non » dans la macro elle-même.

Codes LISP.cuixRécupération d’informations...

I thank you for all your advice
for order creation with icon, I manage.
I have bricscad 2024. It's quite simple to do on Bricscad.
for my problem I found another solution,
I found another lisp which did the same thing as my first lisp and which has no influence on it, so it's all good for me
Thank you so much....

Link to comment
Share on other sites

13 hours ago, Jonathan Handojo said:

 

FYI @mhupp, using macros would've sufficed just as well. Instead of "Yes" and "No", you can use "\\" and create a macro called KeepHmirror and DeleteHmirror in which you fix the inputs "Yes" and "No" into the macro itself.

 

Are you not doing the same thing I suggested with these calls?

 

(defun c:1pm-h nil (OnePointMirror 0 "No"))

 

 

Link to comment
Share on other sites

Using pop menus rather than ribbon is very easy to have choices. Another as you want 4 choices is use a custom dcl with 4 squares so pick the one you want, uses slides for the images.

This is 3x3

image.png.5d2b6ffd06ec7f874a0e5efbad937524.png

 

Edited by BIGAL
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...