Author Topic: Visual Placement  (Read 5331 times)

0 Members and 1 Guest are viewing this topic.

Oak3s

  • Guest
Visual Placement
« on: August 31, 2010, 08:31:26 PM »
I have seen a lot of awesome examples from Lee Mac, Andrea and others where you see some entity following your cursor before you place it. Things like text or plines act like inserting a block. I think this is using grread. Not sure. I am hoping someone will post a simple example I can chew on and try to comprehend as the routines I have seen that use this 'visual placement' are way beyond me.

Kind of like Lee Mac's incremental numbering tool: http://www.theswamp.org/index.php?topic=28727.0

The info is in that code but MAN is that so far beyond me.

How about drawing a rectangle and then picking its 'insertion' point? Would someone please give that example? :) maybe with some awesome comments also :)

Any help is appreciated.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Visual Placement
« Reply #1 on: August 31, 2010, 08:37:43 PM »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Oak3s

  • Guest
Re: Visual Placement
« Reply #2 on: August 31, 2010, 09:50:15 PM »
 :-( Bummer, if that was 'fairly' simple :)

I am trying to go through that and draw a rectangle 2x2. So far I am not very far at all :)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Visual Placement
« Reply #3 on: August 31, 2010, 10:04:39 PM »

What are you having trouble with ??

Care to post what you have so far ??
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Visual Placement
« Reply #4 on: August 31, 2010, 10:16:33 PM »
Keep in mind you cannot natively use osnaps with grread...

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Visual Placement
« Reply #5 on: August 31, 2010, 10:53:42 PM »

Perhaps build on this :

Code: [Select]


(defun c:Doit (/ _Draw_rect done  bw bh wpx  woff hoff ll lr ul ur  gr key data tp)
  ;;
  ;; Codehimbelonga kdub 2010.09.01
  ;;
  (setq bw   5.
        bh   5.
        done nil
        woff (* bw 0.5)
        hoff (* bh 0.5)
  )
  ;;----------------------
  (defun _Draw_rect (/)
    ;; determine the corners relative to te=he cursor location
    ;;
    (setq ll (mapcar '+ (list (- woff) (- hoff) 0.) data)
          lr (mapcar '+ (list woff (- hoff) 0.) data)
          ul (mapcar '+ (list (- woff) hoff 0.) data)
          ur (mapcar '+ (list woff hoff 0.) data)
    )
    (redraw)
    (grdraw ll lr -1 1)
    (grdraw lr ur -1 1)
    (grdraw ur ul -1 1)
    (grdraw ul ll -1 1)
  )
  ;;----------------------
  (prompt "\nSelect Rectangle location")
  (while (not done)
    (setq gr   (grread 't 9 1)
          key  (car gr)
          data (cadr gr)
    )
    (cond ((and (= 5 key) (listp data))
           ;; pointing device and 3Dpoint data
           (_Draw_rect)
          )
          ((and (= 3 key) (listp data))
           ;; Point Selected and 3Dpoint data
           (setq tp data)
           (setq done t)
          )
          ((= 2 key) (setq done t))
    )
  )
  (if tp
    (vl-cmdf "_.Circle" tp woff )
  )
  (redraw)
  (princ)
)
 (prompt "\nDOIT to start")
(princ)

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Oak3s

  • Guest
Re: Visual Placement
« Reply #6 on: August 31, 2010, 10:55:17 PM »
Thanks ronjohp for the reminder. I have read about that in previous posts.

Kerry, what I have so far is not working. I am trying to cut out from your 'simple' ;) example what is not needed. I am focusing on making a rectangle that is 2x2. What I am beginning to grasp from your code is:
Code: [Select]
   (setq gr   (grread 't 9 1)
          key  (car gr)
          data (cadr gr)
    )
So 'data' is the coordinates but I dont know what 'key' is...other than it returns 5 :)

So now I am trying to base my points to draw off of those coordinates. I dont have anything worth posting for that yet.

Oak3s

  • Guest
Re: Visual Placement
« Reply #7 on: August 31, 2010, 10:57:08 PM »
That last example is way easier for me to follow. Thanks.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Visual Placement
« Reply #8 on: August 31, 2010, 11:06:29 PM »
Return Values from grread (from the Help File

The grread function returns a list whose first element is a code specifying the type of input. The second element of the list is either an integer or a point, depending on the type of input. The return values are listed in the following table:

http://docs.autodesk.com/ACD/2011/ENU/filesALR/WS1a9193826455f5ff1a32d8d10ebc6b7ccc-69ed.htm

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Visual Placement
« Reply #9 on: August 31, 2010, 11:24:52 PM »

To answer your next question :
There are several excellent examples of drawing a polyline on the forum

This is an ordinary one :)
http://www.theswamp.org/index.php?topic=34452.msg397246#msg397246
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Oak3s

  • Guest
Re: Visual Placement
« Reply #10 on: August 31, 2010, 11:27:43 PM »
Thanks Kerry. The 5 makes sense. I was actually reading that when you responded. As for the polyline, I think I can cover that part. Its this preview effect I am really trying to achieve. Thanks for the input so far. Hopefully I can post what I come up with tomorrow.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Visual Placement
« Reply #11 on: September 01, 2010, 01:23:11 AM »
Maybe this will help you a bit:


Code: [Select]
(defun c:xx (/ getmidpt e n o p p1 p2 pts x)
  (defun getmidpt (p1 p2) (mapcar '(lambda (x) (* x 0.5)) (mapcar '+ p1 p2)))
  (setq p1 (getpoint "\nSpecify first corner point: "))
  (setq p2 (getcorner p1 "\nSpecify other corner point: "))
  (command "_rectangle" p1 p2)
  (setq e (entlast)
o (vlax-ename->vla-object e)
n 0
  )
  (while ;;while tracking or TAB is pressed loop
(and (setq p (grread 5)) (or (= (car p) 5) (equal p '(2 9))))
    ;;Update polyline coords
    (setq pts (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= 10 (car x))) (entget e)))
 ;;Append midpoints to list
 pts (append pts
     (list (getmidpt (nth 0 pts) (nth 2 pts)))
     (list (getmidpt (nth 0 pts) (nth 1 pts)))
     (list (getmidpt (nth 1 pts) (nth 2 pts)))
     (list (getmidpt (nth 2 pts) (nth 3 pts)))
     (list (getmidpt (nth 3 pts) (nth 0 pts)))
     )
 ;;grab index pt (if greater than 8 go back to zero)
 p1  (nth (if (> n 8)
    (setq n 0)
    n
  )
  pts
     )
    )
    (if (= (car p) 2)
      ;;Tab was pressed step index pt
      (setq n (1+ n))
      ;;Follow cursor
      (vla-move o (vlax-3d-point p1) (vlax-3d-point (cadr p)))
    )
    (princ "\rPress TAB to change insertion point: ")
  )
  (princ)
)
« Last Edit: September 01, 2010, 01:34:00 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Visual Placement
« Reply #12 on: September 01, 2010, 05:50:29 AM »
Just a thought:
It is of course also possible to create a temp block, have the user insert the block and then explode the insert. Especially if you want to "visually place" complex entities such as texts or the circles in Kerry's example, the visual cue would be more exact. You would show the real thing instead of just a bounding box.

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Visual Placement
« Reply #13 on: September 01, 2010, 02:09:24 PM »
As you've probably guessed, I was hooked on the grRead loops for a bit because of the unique 'dynamic' effect. But the downside is the loss of OSnaps, Tracking, Ortho and pretty much every other standard functionality without 'imitating' it in the loop (which can be CPU intensive depending on how far you take it).

Hence I would usually only use these grRead engine programs for such tasks as text placement (see Incremental Numbering Tool - NumInc.lsp), where OSnap may not be always used. But even in these examples, I still provide an option to switch off the dynamic effect to allow use of OSnap.

Lee

Oak3s

  • Guest
Re: Visual Placement
« Reply #14 on: September 01, 2010, 04:12:47 PM »
After playing with this for a little bit and reading all the comments I have learned a little more...and not just about grread. I think I am going to explore the method roy suggested (temp blocks) mostly for the functionality of osnaps. I breifly read a thread about using osnaps with grread and didnt think it was going to be that much of a hurdle......at this point for me though, it probably would be :)

Thanks again for the input. Seems like every time I post a question I get pretty good feedback and information and come away with a bit more knowledge. Very much appreciated you guys. Thanks.