Jump to content

Rubber band effect with more than 2 points


Recommended Posts

Posted

Hello

How would I create the rubber band effect with more than 2 points?

I my case I have 4 points. The user picks 4 points but I would also like to draw a temporary line

between points to show where the user is picking.

thanks

Posted

I think you have answered your own question only diff is that I would draw a pline then erase last

 

something like (not actual code)

(setq pt1 (getpoint))

(command "Pline" pt1)

(while (getpoint))

(command "erase" "L")

Posted

thanks BigAl

I did try something like that but it does not really work.

I want to pick four points eg Pt1 Pt2 Pt3 Pt4 collect the values and draw lines between them.

Your code will pick points then after enter it will draw a pline.

Posted

sample:

 
(setq pt1 (getpoint "\nPick first point:")
       pt2 (getpoint pt1 "\nPick Next point:"))

 

or

 

 
(defun c:test ()
 (setq pt1 (getpoint "\nPick first point:") pt_lst nil)
(while 
 (setq pt2 (getpoint pt1 "\nPick Next point:"))
    (if pt2 (progn
(grdraw pt1 pt2 6 1)
      (setq pt_lst (cons pt2 pt_lst)
      pt1 pt2)))
  )
 )

 

Then draw the pline

 

Hope this helps

:)

Posted

thanks PBe - that's almost what I wanted- however Pt_lst does not seem to generate a points lists. I wanted to pick 4 points of a rectangle - bottom left (Pt1) bottom right (Pt2) top right (Pt3) top left (Pt4)

So my strings would be:

                                     (setq pt1 (getpoint "\nPick bottom left corner:")
                                     (setq pt2 (getpoint "\nPick bottom right corner:")
                                     (setq pt3 (getpoint "\nPick top right corner:")
                                     (setq pt4 (getpoint "\nPick top left corner:")

Posted

really? :)

 

did you try recalling pt_lst varaible?

!pt_lst in commnad prompt

 

or

 

 
(defun c:test ()
 (setq pt1 (getpoint "\nPick first point:") pt_lst nil)
(while 
 (setq pt2 (getpoint pt1 "\nPick Next point:"))
    (if pt2 (progn
(grdraw pt1 pt2 6 1)
      (setq pt_lst (cons pt2 pt_lst)
      pt1 pt2)))
  )
(foreach x pt_lst
  (print x)(princ)
 )
 )

as you can see the pt_lst variable is not nil

 

and I would suggest you use getcorner if its always a rectangle :D no need for grdraw then.

 

try it

Posted

Like this?

(defun grlist (lst / )
 (if (> (length lst) 1)
   (progn
     (grdraw (car lst) (cadr lst) -1 0)
     (grlist (cdr lst))
   )
 )
)

(defun getpoints (msg / pt lst)
 (if (setq pt (getpoint msg))
   (while (and (setq lst (cons pt lst))
               (setq pt (getpoint pt msg))
     )
     (redraw)
     (grlist (cons pt lst))
   )
 )
 (redraw)
 (reverse lst)
)

The getpoints method returns a list of points. The msg is the text displayed through the normal getpoint.

Posted

:shock: I'm so retarded... i did not include the first point ( pt1 ) on the list...

 

Apologies SmallFish.. it does create a list but missing the first point

 

 
(defun c:test ()
(setq pt1 (getpoint "\nPick first point:") pt_lst nil)
  (if pt1 (setq pt_lst (cons pt1 pt_lst))
  )
(while 
 (setq pt2 (getpoint pt1 "\nPick Next point:"))
    (if pt2 (progn
(grdraw pt1 pt2 6 1)
      (setq pt_lst (cons pt2 pt_lst)
      pt1 pt2)))
  )
(foreach x (reverse pt_lst)
  (print x)(princ)
 )
 )

 

 

or Try Irnebs' code, he's got it all covered

Word of cautiion.. if you're planning to use vla-AddLightWeightPolyline remember to convert it to a variant (array of doubles)

this list wont work with that :)

Posted

Hey thanks pbe and Irnb. Now I have it working more less working how I want it, after a bit of adjustment.

Posted
Hey thanks pbe and Irnb. Now I have it working more less working how I want it, after a bit of adjustment.

 

Your welcome, we're happy to help :)

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...