Grread polyline draw with arc option

Grread polyline draw with arc option

office
Enthusiast Enthusiast
4,311 Views
21 Replies
Message 1 of 22

Grread polyline draw with arc option

office
Enthusiast
Enthusiast

I made a lisp that draws a polyline with grread.

I want to switch to arc while drawing the polyline with my grread function.

How can it be made to be the same as the autocad polyline draw arc option while drawing a polyline?

0 Likes
Accepted solutions (1)
4,312 Views
21 Replies
Replies (21)
Message 2 of 22

CodeDing
Advisor
Advisor

@office ,

 

Have you considered this instead?

(command-s "_.PLINE")

 

Best,

~DD

0 Likes
Message 3 of 22

office
Enthusiast
Enthusiast

Not good.

I need grread solution. When the polyline is drawn there is custom options for the polyline and custom objects drawn on thepolyline.

0 Likes
Message 4 of 22

CADaSchtroumpf
Advisor
Advisor

Try to integrate this for arc?:

((lambda ( / p1 p2 ll pt_m px1 px2 key p3 px3 px4 pt_cen rad inc ang nm lst_pt pa1 pa2)
  (initget 9)
  (setq p1 (getpoint "\nFirst point: "))
  (initget 9)
  (setq p2 (getpoint p1 "\nNext point: "))
  (setq
    ll (list p1 p2)
    pt_m
    (mapcar
      '/
      (list
        (apply '+ (mapcar 'car ll))
        (apply '+ (mapcar 'cadr ll))
        (apply '+ (mapcar 'caddr ll))
      )
      '(2.0 2.0 2.0)
    )
    px1 (polar pt_m (+ (angle p1 p2) (* pi 0.5)) (distance p1 p2))
    px2 (polar pt_m (- (angle p1 p2) (* pi 0.5)) (distance p1 p2))
  )
  (princ "\nLast point: ")
  (while (and (setq key (grread T 4 0)) (/= (car key) 3))
    (cond
      ((eq (car key) 5)
        (redraw)
        (setq
          p3 (cadr key)
          ll (list p1 p3)
          pt_m
          (mapcar
            '/
            (list
              (apply '+ (mapcar 'car ll))
              (apply '+ (mapcar 'cadr ll))
              (apply '+ (mapcar 'caddr ll))
            )
            '(2.0 2.0 2.0)
          )
          px3 (polar pt_m (+ (angle p1 p3) (* pi 0.5)) (distance p1 p3))
          px4 (polar pt_m (- (angle p1 p3) (* pi 0.5)) (distance p1 p3))
          pt_cen (inters px1 px2 px3 px4 nil)
        )
        (cond
          (pt_cen
            (setq 
              rad (distance pt_cen p3)
              inc (angle pt_cen p1)
              ang (+ (* 2.0 pi) (angle pt_cen p3))
              nm (fix (/ (rem (- ang inc) (* 2.0 pi)) (/ (* pi 2.0) 36.0)))
              lst_pt '()
            )
            (if (zerop nm) (setq nm 1))
            (repeat nm
              (setq
                pa1 (polar pt_cen inc rad)
                inc (+ inc (/ (* pi 2.0) 36.0))
                pa2 (polar pt_cen inc rad)
                lst_pt (append lst_pt (list pa1 pa2))
              )
            )
            (setq lst_pt (append lst_pt (list pa2 p3)))
            (grvecs lst_pt)
          )
        )
      )
    )
  )
  (prin1)
))
Message 5 of 22

office
Enthusiast
Enthusiast

Interesting but it is not acting the same as the polyline arc option. 🤔

https://through-the-interface.typepad.com/through_the_interface/2010/12/jigging-an-autocad-polyline-...

This one is a .net sample and works perfect.

0 Likes
Message 6 of 22

CodeDing
Advisor
Advisor

@office ,

 

As Kean stated in the link you provided.. 

 

"...this implementation is some way from re-implementing the full PLINE command..."

 ..it may become evident about just HOW HARD it would be to provide you with a full solution. Kean's code is already quite lengthy and is also written in a MUCH more capable language..

 

If you choose to continue toward a solution with LISP then some sacrifices will be made (you may already know this since you *presumably already have some code attempting to create PLINE segments while also using the grread function). 

 

Without knowing the full extent of your current code, I would possibly try an approach using a combination of getpoint and entmake inside of a while loopYou will not get transient graphics this way but that's one of the sacrifices to be made when using LISP. 

 

Maybe you can give us more information as to what your full program is trying to accomplish and we can suggest some alternate approaches? I'm not sure what benefit you're trying to accomplish by using grread and creating polylines anyways? grread does not support snaps.. and even if you are using Lee's grsnap function it would still appear to be a large recreation of the PLINE command, when it may not be necessary..

 

Best,

~DD

0 Likes
Message 7 of 22

Sea-Haven
Mentor
Mentor

This may be useful its dynamic change a fillet. By Cad guru   ;; Alan J. Thompson

 

 

0 Likes
Message 8 of 22

office
Enthusiast
Enthusiast

Here is 2 screenshots.

Grread1.png

 

 

 

 

 

 

 

 

 

 

Grread2.png

 

 

 

The red line, red arrow and red circle is the grdraw and when I click the polyline coordinates are updated and there is inserted an arrow and a circle. And here I need the arc option.

At the command prompt I have custom options.

For osnap in the grread loop I use  (setq osnapPoint (osnap grPoint "_end,_nea")) and if the osnapPoint not nil it means osnap is found and I draw to osnapPoint and not to grPoint.

 

0 Likes
Message 9 of 22

ВeekeeCZ
Consultant
Consultant

What's the workflow? Is there any point where is required to change the custom setting during drawing a polyline?

0 Likes
Message 10 of 22

office
Enthusiast
Enthusiast

When you press 'a' and enter or space it should switch to arc draw.

There are other options too, like angle step, if you set it to 5 degrees, the grdraw is drawing in only in every 5 degrees.

The main problem is to be able to switch to arc like the autocad's polyline drawing arc option.

0 Likes
Message 11 of 22

ВeekeeCZ
Consultant
Consultant

My question was heading elsewhere - is the whole thing with 'grread' even worth it?

 

(defun c:PlineAdvanced ( / opt)
  
  (setq opt (getpoint "\nStart a polyline or [Pipe data/Draw options]: "))
  (if (= 'list (type opt)) (command-s "_.pline" "_non" opt))
  (setq opt (getkword "\nAdjust the setting [Pipe data/Draw options] <done>: "))
  (princ)
 )
0 Likes
Message 12 of 22

office
Enthusiast
Enthusiast

Grread1.png

 

 

 

 

 

 

 

 

 

 

 

I need to draw with grread line, triangle and circle as you see the red objects on the screenshot . So this is why I use the grread to draw mi custom object. And here would be nice the arc option with grread.

0 Likes
Message 13 of 22

ВeekeeCZ
Consultant
Consultant

Definitely. That would be nice if it weren't so complicated.

I could be wrong. Someone could surprise me and dive into geometry books for a couple of hours and make the code done. My guess is this is not going to happen. Better think of alternatives.

Good luck!

 

0 Likes
Message 14 of 22

doaiena
Collaborator
Collaborator

If i'm understanding you correctly, you want a polyline with direction arrows in the middle of each segment and circles at each vertex. If that is the case, why not draw a normal polyline and then just add these graphics after the pline is done.

0 Likes
Message 15 of 22

dlanorh
Advisor
Advisor

@office wrote:

Interesting but it is not acting the same as the polyline arc option. 🤔

https://through-the-interface.typepad.com/through_the_interface/2010/12/jigging-an-autocad-polyline-...

This one is a .net sample and works perfect.


It is not possible to draw an "arc" using "grread" and "grdraw" as "grdraw" can only draw a vector between two points, see HERE , so you will never get an arc segment, only a series of straight lines approximating an arc.

I am not one of the robots you're looking for

0 Likes
Message 16 of 22

hak_vz
Advisor
Advisor

@doaiena wrote:

If i'm understanding you correctly, you want a polyline with direction arrows in the middle of each segment and circles at each vertex. If that is the case, why not draw a normal polyline and then just add these graphics after the pline is done.


I agree. It can only be a nice looking visual effect. If it can be achieved it would take some serious coding. Question is if this question is needed in a production program or is asked just "for fun".

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 17 of 22

ronjonp
Mentor
Mentor

Maybe THIS will give you some ideas. As stated before why is grread necessary?

0 Likes
Message 18 of 22

ronjonp
Mentor
Mentor

Quick example only using circles with 0.1 size radius:

(defun c:foo (/ _drawpolyline e i)
  ;; RJP » 2019-12-19
  (defun _drawpolyline (/ a r)
    (setq a (entlast))
    (if	(vl-catch-all-error-p
	  (vl-catch-all-apply
	    '(lambda (/)
	       (vl-cmdf "_.pline")
	       (while (> (getvar 'cmdactive) 0) (command "\\"))
	       (or (equal a (entlast)) (setq r (entlast)))
	     )
	  )
	)
      (progn (princ "\nUndid start point!! Bye!") (command))
      r
    )
  )
  (cond	((setq e (_drawpolyline))
	 (setq i 0)
	 (entmod (append (entget e) '((62 . 1))))
	 (while	(<= i (vlax-curve-getendparam e))
	   (entmakex (list '(0 . "circle")
			   '(8 . "circlelayer")
			   '(40 . 0.1)
			   (cons 10 (vlax-curve-getpointatparam e i))
		     )
	   )
	   (setq i (+ 0.5 i))
	 )
	)
  )
  (princ)
)

 

0 Likes
Message 19 of 22

Sea-Haven
Mentor
Mentor

My time and effort is on your answer.

0 Likes
Message 20 of 22

office
Enthusiast
Enthusiast
Accepted solution

Thank you all for your answers.

I made the polyline draw with arc support using grread.

Thanks to CADaStroumph's arc sample, I made some changes to that function to be the same as the polyline arc option.

I attached the lisp file. You can try it.

It works only in World UCS.

0 Likes