Author Topic: Add Mirror Option  (Read 5485 times)

0 Members and 1 Guest are viewing this topic.

Oak3s

  • Guest
Add Mirror Option
« on: October 22, 2010, 06:33:20 PM »
Over time I have been able to put the following together. It doesnt account for errors at this point. What it does do is draw a rectangle that is 0.5 tall. It asks for a width. I use acet-ss-drag-move so that a user can see where it will be placed before the point is selected.
I would appreciate some help as to how to add a mirror option. The idea would be to hit spacebar and the vector from acet-ss-drag-move would mirror/flip about the Y axis.
Any ideas.
Code: [Select]
(defun c:Plate (/ Thick Wide tPT PT1 PT2 PT3 InsPT ss)
(defun DTR (A) (* pi (/ A 180.0)))
(setvar "CMDECHO" 0)
(setvar "OSMODE" 0)
(setq Thick 0.5
     Wide (getint "\nEnter Plate Width in Inches: ")
     tPT (list 0. 10000. 0.)
     PT1 (polar tPT (DTR 90) Thick)
     PT2 (polar PT1 (DTR 0) Wide)
     PT3 (polar PT2 (DTR 270) Thick)
)
(vl-cmdf "pline" tPT PT1 PT2 PT3 tPT "")
(setq ss (ssadd))
(ssadd (entlast) ss)
(setq InsPT (acet-ss-drag-move ss tPT "\nSelect base point: " ))
(vl-cmdf "_.Move" ss "" tPT InsPT)
(princ)
)
*Edited by Oak3s 10.22.10

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Add Mirror Option
« Reply #1 on: October 22, 2010, 06:36:01 PM »
What version of CAD are you on? This a task easily accomplished with a dynamic block.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Oak3s

  • Guest
Re: Add Mirror Option
« Reply #2 on: October 22, 2010, 06:41:42 PM »
v2011

I looked at doing this by inserting a DB yesterday but I havent gotten back to that today. This is how I have been doing it and just started exploring the DB idea.
My idea was 'I can follow this code pretty well...I have to look up every line of Visual LISP and so far the options I have found for modifying a DB have been VL. I am getting there but my big hangup has been trying to get the name through (entlast) rather than (entsel)...I will find the code to give you a better idea of what I am talking about. I believe it was Lee Mac and T.Willey I was getting info from.

Oak3s

  • Guest
Re: Add Mirror Option
« Reply #3 on: October 22, 2010, 06:46:52 PM »
The following basically came from T.Willey
http://www.theswamp.org/index.php?topic=31549.0
All I added was the function call, vl-load-com, and set the object to ob2.
Other than that I tried to change the property to "Width" and the value to 6...but no go.
Code: [Select]
(defun c:dyn (/)
(vl-load-com)
(setq ob2 (vlax-ename->vla-object(car(entsel))))
(foreach i
(vlax-invoke-method ob2 'getdynamicblockproperties)
(if (= "Width" (vla-get-PropertyName i))
        (vla-put-Value i 6)
)
)
)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Add Mirror Option
« Reply #4 on: October 22, 2010, 07:00:29 PM »
I posted in the thread linked to, so if that doesn't help you, let us know.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Oak3s

  • Guest
Re: Add Mirror Option
« Reply #5 on: October 22, 2010, 07:14:28 PM »
I noticed. Thank you.

I would be just as satisfied to have this method allow for a mirror option though. Either way I will learn something :)

Oak3s

  • Guest
Re: Add Mirror Option
« Reply #6 on: October 22, 2010, 10:21:17 PM »
What version of CAD are you on? This a task easily accomplished with a dynamic block.

Could you elaborate?

Insert block at some crazy point.
Then acet-ss-drag-move and have the option
to hit spacebar to 'flip' it?

or

insert block (visually see it at cursor) and flip it while it is actually there?

The goal is to see the entity before selecting its point.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Add Mirror Option
« Reply #7 on: October 23, 2010, 12:23:04 PM »
What version of CAD are you on? This a task easily accomplished with a dynamic block.

Could you elaborate?

Insert block at some crazy point.
Then acet-ss-drag-move and have the option
to hit spacebar to 'flip' it?

or

insert block (visually see it at cursor) and flip it while it is actually there?

The goal is to see the entity before selecting its point.

Give this block a try .. might be able to help out some more later.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Add Mirror Option
« Reply #8 on: October 25, 2010, 05:41:18 PM »
Did this block not work for you?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Oak3s

  • Guest
Re: Add Mirror Option
« Reply #9 on: October 26, 2010, 01:07:32 PM »
The block works nicely. However my options on insert are to scale and/or rotate. The block itself can flip but I would like the option during insert (or a modified version of insert).

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Add Mirror Option
« Reply #10 on: October 26, 2010, 03:15:57 PM »
See if this works how you want ... this is how I'd approach what I think you want (I'd still use a block):


Code: [Select]
(defun c:plate (/ ce e el h w xs)
  (defun mkblk ()
    (and (not (tblobjname "block" "square"))
(entmake '((0 . "BLOCK")
    (100 . "AcDbEntity")
    (8 . "0")
    (100 . "AcDbBlockReference")
    (2 . "square")
    (10 0.0 0.0 0.0)
    (70 . 0)
   )
)
(entmake '((0 . "LWPOLYLINE")
    (100 . "AcDbEntity")
    (8 . "0")
    (100 . "AcDbPolyline")
    (90 . 4)
    (70 . 129)
    (43 . 0.0)
    (10 0.0 1.0)
    (10 0.0 0.0)
    (10 1.0 0.0)
    (10 1.0 1.0)
   )
)
(entmake '((0 . "ENDBLK") (100 . "AcDbBlockEnd") (8 . "0")))
    )
  )
  (if (and (setq w (getdist "\nEnter Plate Width in Inches: "))
   (setq h 0.5)
   (setq ce (getvar 'cmdecho))
   ;;(setq hgt (getdist "\nEnter Plate Height in Inches: "))
      )
    (progn (mkblk)
   (setvar 'cmdecho 0)
   (vl-cmdf ".-insert" "square" "X" w "Y" h "R" 0.0 pause)
   (if (and (setq e (entlast))
    (setq el (entget e))
    (= (cdr (assoc 2 el)) "square")
    (equal (cdr (assoc 10 el)) (getvar 'lastpoint))
       )
     (while (getpoint "\nPick a point to flip plate or enter to end: ")
       (setq xs (assoc 41 el))
       (setq el (entmod (subst (cons 41 (- (cdr xs))) xs el)))
     )
   )
   (setvar 'cmdecho ce)
    )
  )
  (princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Oak3s

  • Guest
Re: Add Mirror Option
« Reply #11 on: October 26, 2010, 04:41:33 PM »
that works really well but it doesnt off the 'flip' when I would like it to be offered. I appreciate the code and I am not asking someone to write it for me. I just dont know where to start.

You know when you insert a block and the comman line reads:
Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]

I would like it to read with the options of:
[Rotate/Flip] and have flip be initiated by just hitting spacebar. This all takes place before specifying the insertion point.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Add Mirror Option
« Reply #12 on: October 26, 2010, 05:30:43 PM »
The flip can be added in a grread loop before the block is placed but I would not go that route for lack of snaps. The more I travel down the rabbit hole the more I'm convinced a dynamic block would be the answer.

You have a sample drawing?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Oak3s

  • Guest
Re: Add Mirror Option
« Reply #13 on: October 26, 2010, 05:52:06 PM »
When you say a dynamic block would be the answer are you referring to the functionality after the block is placed or before?

Either way the end product will be just lines. At the moment company standard is entities such as this are not blocks. It can be a block to place it (so the functionality of inserting is used) but after that it will be plines.

I apologize if I am missing something...I sure feel like I am because I am repeating myself a lot :).

Also...I may be missing something when I insert a DB. I looks to me like the same options are available when inserting a regular block or a DB...do you have the DB properties available to you?

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Add Mirror Option
« Reply #14 on: October 26, 2010, 06:03:11 PM »
The dynamic block has the functionality after it is placed (but there are a lot of cool quick editing features).

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Oak3s

  • Guest
Re: Add Mirror Option
« Reply #15 on: October 26, 2010, 08:01:13 PM »
I am not getting the desired function from the code below. This is not the 'block' method.
I though acet-ss-drag-move honored initget settings so I tried to add a flip keyword and have that flip my selection set, but I am not getting it. Help please  :cry:

Code: [Select]
(defun c:cShape (/ dynPT Thick Wide sWide Tall sTall tPT InsPT PT1 PT2 PT3 PT4 PT5 PT6 PT7 ss)
(defun DTR (A) (* pi (/ A 180.0)))
(setvar "CMDECHO" 0)
(setvar "OSMODE" 0)
(setq Thick 0.5
Wide (getint "\nEnter C Shape Width in Inches: ")
sWide (- Wide Thick)
Tall (getint "\nEnter C Shape Height in Inches: ")
sTall (- Tall (* 2 Thick))
tPT (list 0. 10000. 0.)
PT1 (polar tPT (DTR 90) Tall)
PT2 (polar PT1 (DTR 0) Wide)
PT3 (polar PT2 (DTR 270) Thick)
PT4 (polar PT3 (DTR 180) sWide)
PT5 (polar PT4 (DTR 270) sTall)
PT6 (polar PT5 (DTR 0) sWide)
PT7 (polar PT6 (DTR 270) Thick)
)
(vl-cmdf "pline" tPT PT1 PT2 PT3 PT4 PT5 PT6 PT7 tPT "")
(setvar "OSMODE" saOSM)
(setq ss (ssadd))
(ssadd (entlast) ss)
(initget 2 "Flip")
(setq InsPT (acet-ss-drag-move ss tPT "\nSelect base point <Flip>: " ))
(if (= InsPT "Flip")
((vl-cmdf "_mirror" ss "" tPT PT1 "Y")(setq InsPT (acet-ss-drag-move ss tPT "\nSelect base point: " ))(vl-cmdf "_.Move" ss "" tPT InsPT))
(vl-cmdf "_.Move" ss "" tPT InsPT)
)
(princ)
)

*Edited by Oak3s 10.26.10

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
Re: Add Mirror Option
« Reply #16 on: October 26, 2010, 08:13:31 PM »
I'm with ronjonp on this a dynamic Block with a FLIP option built in would be a good thing.
Be your Best


Michael Farrell
http://primeservicesglobal.com/

Oak3s

  • Guest
Re: Add Mirror Option
« Reply #17 on: October 26, 2010, 08:28:40 PM »
 :lol: Either way would be fine with me as long as the flip option can occur before placement. How to accomplish such a thing is where my problem is.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Add Mirror Option
« Reply #18 on: October 26, 2010, 10:53:54 PM »
:lol: Either way would be fine with me as long as the flip option can occur before placement. How to accomplish such a thing is where my problem is.

Is this an extension from this post?

http://www.theswamp.org/index.php?topic=34714.msg399534#msg399534

There is your placement sans the snaps  :-P

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Oak3s

  • Guest
Re: Add Mirror Option
« Reply #19 on: October 28, 2010, 01:44:24 PM »
Not exactly but in the example you posted you show the type of effect I am looking for...except grread kills the osnaps I need. What I learned from that thread was acet-ss-drag-move. Now only if I can get a 'flip' option.

Oak3s

  • Guest
Re: Add Mirror Option
« Reply #20 on: October 29, 2010, 04:46:11 PM »
No new ideas? Bummer  :oops:

I was thinking that if acet-ss-drag-move got something other than a point it would in a sense cancel the move. The idea seems good to me. I just dont know how to write the code for it.

Code: [Select]
(initget 2 "Flip")
(setq InsPT (acet-ss-drag-move ss tPT "\nSelect base point <Flip>: " ))
(if (= InsPT "Flip")
((vl-cmdf "_mirror" ss "" tPT PT1 "Y")(setq InsPT (acet-ss-drag-move ss tPT "\nSelect base point: " ))(vl-cmdf "_.Move" ss "" tPT InsPT))
(vl-cmdf "_.Move" ss "" tPT InsPT)
)

This is a snip from the code. The idea is to 'preview' the move with acet-ss-drag-move but if flip is activated cancel the drag-move - mirror the ss - start the drag-move again but with a 'flipped' preview. Is this though process doable?

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Add Mirror Option
« Reply #21 on: October 29, 2010, 07:06:30 PM »
Do you have a sample drawing? I'm having a hard time thinking about this order of input when you have so many other tools at your advantage.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Add Mirror Option
« Reply #22 on: October 30, 2010, 10:12:48 AM »
You need to use (initget 128 )  for your option to work.
I added a Flip option to this routine for you to try. Did not do much error checking.
Code: [Select]
;;; MOCOROSC.lsp
;;;   Move, Copy, Rotate, Scale the selection set.
;;;
;;;   This routine makes use of the express tools routines acet-ss-drag-move,
;;;   acet-ss-drag-rotate, acet-ss-drag-scale, found in "acetutil.arx" and
;;;   assumes it has been loaded with (arxload "acetutil").
;;;   Parameters passed to this routine are the selection set of objects and
;;;   a base point. Nothing is returned by this routine.
;;;
(defun mocorosc (ss p1 / na p2 n d p lst j p3)
  (setq p2 t)
  (setq n 0)
  ;;  *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  ;;                   Main Loop                   
  ;;  *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  (while p2
    (setq na (entlast))
    (if (not lst)
      (setq lst (list (list ss p1)))
    ) ;if
    (setvar "lastpoint" p1)
    (acet-ss-redraw ss 3)
    (initget 128 "Rotate Scale Base Undo eXit")
    (setq p2 (acet-ss-drag-move
               ss
               p1
               "\nSecond point or \n[Rotate/Scale/Base/Flip/Undo] <exit>: "
               nil
             ) ;acet-ss-drag-move
    ) ;setq
    (acet-ss-redraw ss 4)
    ;;  if p2 is a point a copy is made
    (if (= p2 "eXit")
      (setq p2 nil)
    ) ;if
    (cond
      ((= p2 "Undo")
       (if (= n 0)
         (princ "\nNothing to undo.")
         (progn
           (command "_.undo" "1")
           (setq n   (- n 1)
                 lst (cdr lst)
                 ss  (car lst)
                 p1  (cadr ss)
                 ss  (car ss)
           ) ;setq
         ) ;progn else
       ) ;if
      ) ;cond #1
      ;;===================   SCALE  ======================
      ((= p2 "Scale")
       (initget 128 "Rotate Scale Base Undo eXit")
       (setq p2 (acet-ss-drag-scale
                  ss
                  p1
                  "\nSecond point or \n[Rotate/Scale/Base/Undo] <exit>: "
                  nil
                ) ;acet-ss-drag-move
       ) ;setq
       (if (and (= (type p2) 'real) (/= p2 0))
         (progn
           (command "_.scale" ss "" p1 p2)
           (setq n   (+ n 1)
                 lst (cons (list ss p1) lst)
           ) ;setq
         )
       )
      ) ;cond #2

      ;;===================   COPY  ======================
      ((equal 'list (type p2))
       (command "_.copy" ss "" p1 p2)
       (setq n   (+ n 1)
             ss  (acet-ss-new na)
             p1  p2
             lst (cons (list ss p1) lst)
       ) ;setq
      ) ;cond #3

      ;;===================   ROTATE  ======================
      ((= p2 "Rotate")
       (initget 128 "Rotate Scale Base Undo eXit")
       (setq p2 (acet-ss-drag-rotate
                  ss
                  p1
                  "\nSecond point or \n[Rotate/Scale/Base/Undo] <exit>: "
                  nil
                ) ;acet-ss-drag-move
       ) ;setq
       (if (= (type p2) 'real)
         (progn
           (command "_.rotate" ss "" p1 (* 180.0 (/ p2 pi)))
           (setq n   (+ n 1)
                 lst (cons (list ss p1) lst)
           ) ;setq
         )
       )
      ) ;cond #4

      ;;===================   BASE  ======================
      ((= p2 "Base")
       (setq p (getpoint "\nPick a new Base Point."))
       (if (and p (= (type p) 'list))
         (setq p1  p
               n   (+ n 1)
               lst (cons (list ss p1) lst)
         )
       )
      ) ;cond #5

      ;;===================   FLIP  ======================
      ((member p2 '("f" "F"))
       (command "_.mirror" ss "" "non" p1 "non" (polar p1 (/ pi 2) 10) "Y")
       )
     
      ;;===================   ERROR  ======================
      (p2
       (princ "\nInvalid input.")
      ) ;cond #6

    ) ;cond close
  ) ;while
  ;;  *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

) ;defun

(defun c:test (/ ss p)
  (prompt "\nSelect objects:")
  (if (and (setq ss (ssget))
           (setq p (getpoint "\Pick base point:"))
      )
    (mocorosc ss p)
  )
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Oak3s

  • Guest
Re: Add Mirror Option
« Reply #23 on: November 02, 2010, 01:49:40 PM »
Thats CAB. I did a quick test of what you posted and it looks like it does exactly what I am looking for. I may post again on this topic once I get some time to dig into the code again. I am kinda busy at the moment.

Thank you again.