Jump to content

Help Creating an ARC lisp


PAWEL17

Recommended Posts

How do i go about creating a lisp for an ARC command.

 

I want to be able to draw an ARC around a point the same every time,

50mm radius with a 270 degree arc around a point.

I Just want to input the command and select the point.

 

I have been able to do one for a simple circle. But im struggling to follow the tutorials on this site.

 

Help would be appreciated

Link to comment
Share on other sites

This should do what you're looking for.

 

(vl-load-com)

   (defun c:tt ( / ms pt )
     (setq ms (vla-get-modelspace(vla-get-activedocument(vlax-get-acad-object)))
             pt (vlax-3d-point(getpoint "Select insertion point")))
     ;(vla-addArc model-space insertion-point radius start-angle end-angle)
     (vla-addArc ms pt 50 0 270)
   )

Link to comment
Share on other sites

I would suggest looking into (entmake) :

 

[b][color=BLACK]([/color][/b]defun c:sarc [b][color=FUCHSIA]([/color][/b]/ ce ra sa ia cl[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]initget 1[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq ce [b][color=NAVY]([/color][/b]getpoint [color=#2f4f4f]"\nARC Center Point:   "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]setq ra 50      [color=#8b4513];Radius[/color]
       sa 0       [color=#8b4513];Start Angle[/color]
       ia 270     [color=#8b4513];Included Angle[/color]
       cl 256[b][color=FUCHSIA])[/color][/b]    [color=#8b4513];Color[/color]

 [b][color=FUCHSIA]([/color][/b]entmake [b][color=NAVY]([/color][/b]list [b][color=MAROON]([/color][/b]cons 0 [color=#2f4f4f]"ARC"[/color][b][color=MAROON])[/color][/b]
                [b][color=MAROON]([/color][/b]cons 6 [b][color=GREEN]([/color][/b]getvar [color=#2f4f4f]"CELTYPE"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
                [b][color=MAROON]([/color][/b]cons 8 [b][color=GREEN]([/color][/b]getvar [color=#2f4f4f]"CLAYER"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
                [b][color=MAROON]([/color][/b]cons 10 ce[b][color=MAROON])[/color][/b]
                [b][color=MAROON]([/color][/b]cons 39 [b][color=GREEN]([/color][/b]getvar [color=#2f4f4f]"THICKNESS"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
                [b][color=MAROON]([/color][/b]cons 40 ra[b][color=MAROON])[/color][/b]
                [b][color=MAROON]([/color][/b]cons 50 [b][color=GREEN]([/color][/b]* sa [b][color=BLUE]([/color][/b]/ pi 180[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
                [b][color=MAROON]([/color][/b]cons 51 [b][color=GREEN]([/color][/b]* [b][color=BLUE]([/color][/b]+ sa ia[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]/ pi 180[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
                [b][color=MAROON]([/color][/b]cons 62 cl[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

 

It can give almost total control over entity creations

 

-David

Link to comment
Share on other sites

I would stick with David Bethel's suggestion, but to throw another option:

(if (setq pt (getpoint "\nSpecify the center point for the arc: "))
(vl-catch-all-apply 'vl-cmdf (list "_.ARC" "C" "_non" pt "_non" (polar pt (angtof "0") 50) "_non" (polar pt (angtof "270") 50) ))
)

EDIT: And heres another option (evaluating a list):

(defun C:test ( / pt p1 p2 )
(if 
	(setq 
		pt (getpoint "\nSpecify the center point for the arc: ")
		p1 (polar pt (angtof "0") 50)
		p2 (polar pt (angtof "270") 50)
	)
	(eval '(command "_.ARC" "C" "_non" pt "_non" p1 "_non" p2))
)
(princ)
)

Link to comment
Share on other sites

Sorry to pick at your code but -

 

(if (setq pt (getpoint "\nSpecify the center point for the arc: "))
   (vl-catch-all-apply 'vl-cmdf (list "_.ARC" "C" "_non" pt "_non" (polar pt (angtof "0") 50) "_non" (polar pt (angtof "270") 50) ))
)

 

Why the use of vl-catch-all-apply here?

 

EDIT: And heres another option (evaluating a list):

(defun C:test ( / pt p1 p2 )
   (if 
       (setq 
           pt (getpoint "\nSpecify the center point for the arc: ")
           p1 (polar pt (angtof "0") 50)
           p2 (polar pt (angtof "270") 50)
       )
       (eval '(command "_.ARC" "C" "_non" pt "_non" p1 "_non" p2))
   )
   (princ)
)

 

The use of eval seems redundant here - removing the eval function and single quote would produce the same result.

Link to comment
Share on other sites

I would stick with David Bethel's suggestion, but to throw another option:

(if (setq pt (getpoint "\nSpecify the center point for the arc: "))
(vl-catch-all-apply 'vl-cmdf (list "_.ARC" "C" "_non" pt "_non" (polar pt (angtof "0") 50) "_non" (polar pt (angtof "270") 50) ))
)

 

What is the need or the use of the vl-catch-* function in your example?

 

EDIT: And heres another option (evaluating a list):

 

Just hit enter when the program asks you to specify center point.

Link to comment
Share on other sites

Here's another example to account for changes to the UCS:

(defun c:qarc ( / c z )
   (setq z (trans '(0 0 1) 1 0 t))
   (while (setq c (getpoint "\nArc center: "))
       (entmake
           (list
              '(000 . "ARC")
              '(040 . 50.0)
              '(050 .  0.0)
              '(051 .  4.712388980384689)
               (cons 010 (trans c 1 z))
               (cons 210 z)
           )
       )
   )
   (princ)
)

Or with the arc angle aligned to the UCS:

(defun c:qarc ( / a b c z )
   (setq z (trans '(0 0 1) 1 0 t)
         a (angle '(0 0) (trans (getvar 'ucsxdir) 0 z t))
         b (+ a 4.712388980384689)
   )
   (while (setq c (getpoint "\nArc center: "))
       (entmake
           (list
              '(000 . "ARC")
              '(040 . 50.0)
               (cons 050 a)
               (cons 051 b)
               (cons 010 (trans c 1 z))
               (cons 210 z)
           )
       )
   )
   (princ)
)

Link to comment
Share on other sites

I would suggest looking into (entmake) :

 

[b][color=BLACK]([/color][/b]defun c:sarc [b][color=FUCHSIA]([/color][/b]/ ce ra sa ia cl[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]initget 1[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq ce [b][color=NAVY]([/color][/b]getpoint [color=#2f4f4f]"\nARC Center Point:   "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]setq ra 50      [color=#8b4513];Radius[/color]
       sa 0       [color=#8b4513];Start Angle[/color]
       ia 270     [color=#8b4513];Included Angle[/color]
       cl 256[b][color=FUCHSIA])[/color][/b]    [color=#8b4513];Color[/color]

 [b][color=FUCHSIA]([/color][/b]entmake [b][color=NAVY]([/color][/b]list [b][color=MAROON]([/color][/b]cons 0 [color=#2f4f4f]"ARC"[/color][b][color=MAROON])[/color][/b]
                [b][color=MAROON]([/color][/b]cons 6 [b][color=GREEN]([/color][/b]getvar [color=#2f4f4f]"CELTYPE"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
                [b][color=MAROON]([/color][/b]cons 8 [b][color=GREEN]([/color][/b]getvar [color=#2f4f4f]"CLAYER"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
                [b][color=MAROON]([/color][/b]cons 10 ce[b][color=MAROON])[/color][/b]
                [b][color=MAROON]([/color][/b]cons 39 [b][color=GREEN]([/color][/b]getvar [color=#2f4f4f]"THICKNESS"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
                [b][color=MAROON]([/color][/b]cons 40 ra[b][color=MAROON])[/color][/b]
                [b][color=MAROON]([/color][/b]cons 50 [b][color=GREEN]([/color][/b]* sa [b][color=BLUE]([/color][/b]/ pi 180[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
                [b][color=MAROON]([/color][/b]cons 51 [b][color=GREEN]([/color][/b]* [b][color=BLUE]([/color][/b]+ sa ia[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]/ pi 180[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
                [b][color=MAROON]([/color][/b]cons 62 cl[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

 

It can give almost total control over entity creations

 

-David

 

This is excellent, along the lines of what i was trying to create

Is it possible to take the layer of the line/polyline its being created on, instead of having to match properties after its created?

Link to comment
Share on other sites

Maybe

 

[b][color=#ff00ff]([/color][/b]initget 1[b][color=fuchsia])[/color][/b]
(setq clay (cdr (assoc 8 (entget (car (entsel "Pick an object for layer"))))))
 [b][color=fuchsia]([/color][/b]setq ce [b][color=navy]([/color][/b]getpoint [color=#2f4f4f]"\nARC Center Point:   "[/color][b][color=navy])[/color][/b][b][color=fuchsia])[/color][/b]
[b][color=#ff00ff]................[/color][/b]
[b][color=#800000]([/color][/b]cons 8 clay)
................

Link to comment
Share on other sites

Lee, just out of curiosity, why the (trans) call on the center point ?

 

 

Here's another example to account for changes to the UCS:
(defun c:qarc ( / c z )
   (setq z (trans '(0 0 1) 1 0 t))
  
               (cons 010 (trans c 1 z))
               (cons 210 z)
           )
       )
   )
   (princ)
)

 

I can't think of a scenario that would apply. Thanks -David

Link to comment
Share on other sites

To do the operation with a single click would probably take something like this:

 

[b][color=BLACK]([/color][/b]defun c:sarc1 [b][color=FUCHSIA]([/color][/b]/ la ce ra sa ia cl ss a d[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]not ce[b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]initget 1[b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]setq ce [b][color=MAROON]([/color][/b]osnap [b][color=GREEN]([/color][/b]getpoint [color=#2f4f4f]"\nARC Base Point:   "[/color][b][color=GREEN])[/color][/b] [color=#2f4f4f]"NEA,END"[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]cond [b][color=NAVY]([/color][/b][b][color=MAROON]([/color][/b]/= 1 [b][color=GREEN]([/color][/b]sslength [b][color=BLUE]([/color][/b]setq ss [b][color=RED]([/color][/b]ssget [color=#2f4f4f]"C"[/color] ce ce [b][color=PURPLE]([/color][/b]list [b][color=TEAL]([/color][/b]cons 0 [color=#2f4f4f]"*LINE"[/color][b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
        [b][color=MAROON]([/color][/b]alert [color=#2f4f4f]"Multiple LINE Entities Found At This Point"[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
       [b][color=NAVY]([/color][/b]T
        [b][color=MAROON]([/color][/b]setq a [b][color=GREEN]([/color][/b]* pi 0.25[b][color=GREEN])[/color][/b] d [b][color=GREEN]([/color][/b]/ [b][color=BLUE]([/color][/b]getvar [color=#2f4f4f]"VIEWSIZE"[/color][b][color=BLUE])[/color][/b] 33[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
        [b][color=MAROON]([/color][/b]grdraw [b][color=GREEN]([/color][/b]polar ce [b][color=BLUE]([/color][/b]* a 1[b][color=BLUE])[/color][/b] d[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]polar ce [b][color=BLUE]([/color][/b]* a 5[b][color=BLUE])[/color][/b] d[b][color=GREEN])[/color][/b] 6 1[b][color=MAROON])[/color][/b]
        [b][color=MAROON]([/color][/b]grdraw [b][color=GREEN]([/color][/b]polar ce [b][color=BLUE]([/color][/b]* a 3[b][color=BLUE])[/color][/b] d[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]polar ce [b][color=BLUE]([/color][/b]* a 7[b][color=BLUE])[/color][/b] d[b][color=GREEN])[/color][/b] 6 1[b][color=MAROON])[/color][/b]
        [b][color=MAROON]([/color][/b]setq la [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 8 [b][color=RED]([/color][/b]entget [b][color=PURPLE]([/color][/b]ssname ss 0[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [color=#8b4513];Layer[/color]
              ra 50      [color=#8b4513];Radius[/color]
              sa 0       [color=#8b4513];Start Angle[/color]
              ia 270     [color=#8b4513];Included Angle[/color]
              cl 256[b][color=MAROON])[/color][/b]    [color=#8b4513];Color[/color]
        [b][color=MAROON]([/color][/b]entmake [b][color=GREEN]([/color][/b]list [b][color=BLUE]([/color][/b]cons 0 [color=#2f4f4f]"ARC"[/color][b][color=BLUE])[/color][/b]
                       [b][color=BLUE]([/color][/b]cons 6 [b][color=RED]([/color][/b]getvar [color=#2f4f4f]"CELTYPE"[/color][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                       [b][color=BLUE]([/color][/b]cons 8 la[b][color=BLUE])[/color][/b]
                       [b][color=BLUE]([/color][/b]cons 10 ce[b][color=BLUE])[/color][/b]
                       [b][color=BLUE]([/color][/b]cons 39 [b][color=RED]([/color][/b]getvar [color=#2f4f4f]"THICKNESS"[/color][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                       [b][color=BLUE]([/color][/b]cons 40 ra[b][color=BLUE])[/color][/b]
                       [b][color=BLUE]([/color][/b]cons 50 [b][color=RED]([/color][/b]* sa [b][color=PURPLE]([/color][/b]/ pi 180[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                       [b][color=BLUE]([/color][/b]cons 51 [b][color=RED]([/color][/b]* [b][color=PURPLE]([/color][/b]+ sa ia[b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]/ pi 180[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                       [b][color=BLUE]([/color][/b]cons 62 cl[b][color=BLUE])[/color][/b]
                       [b][color=BLUE]([/color][/b]cons 210 [b][color=RED]([/color][/b]trans '[b][color=PURPLE]([/color][/b]0 0 1[b][color=PURPLE])[/color][/b] 1 0[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

 

This would defintlty need testing. And probably more error trapping. -David

Edited by David Bethel
Add forced input
Link to comment
Share on other sites

Lee, just out of curiosity, why the (trans) call on the center point ?

 

I can't think of a scenario that would apply. Thanks -David

 

Since coordinates for most planar entities (with some exceptions) are expressed relative to the Object Coordinate System (OCS), the points must be transformed from the active UCS to the OCS, which may be calculated using the normal vector for the active UCS plane (using the Arbitrary Axis Algorithm, or more conveniently, the trans function).

 

As an example, try the following with the UCS rotated about the Z-axis (by any angle):

(defun c:qarc ( / c z )
   (setq z (trans '(0 0 1) 1 0 t))
   (while (setq c (getpoint "\nArc center: "))
       (entmake
           (list
              '(000 . "ARC")
              '(040 . 50.0)
              '(050 .  0.0)
              '(051 .  4.712388980384689)
              '(062 . 3)
               (cons 010 (trans c 1 z))
               (cons 210 z)
           )
       )
       (entmake
           (list
              '(000 . "ARC")
              '(040 . 50.0)
              '(050 .  0.0)
              '(051 .  4.712388980384689)
              '(062 . 1)
               (cons 010 c)
               (cons 210 z)
           )
       )
   )
   (princ)
)

Link to comment
Share on other sites

  • 3 years later...
On 7/19/2020 at 11:58 AM, Erhanask said:

Well...

radius if we want to give

 

You can add an extra getdist prompt, e.g.:

(defun c:qarc ( / a b c r z )
   (setq z (trans '(0 0 1) 1 0 t)
         a (angle '(0 0) (trans (getvar 'ucsxdir) 0 z t))
         b (+ a 4.712388980384689)
   )
   (while
       (and
           (setq c (getpoint "\nArc center: "))
           (setq r (getdist c "\nSpecify arc radius: "))
       )
       (entmake
           (list
              '(000 . "ARC")
               (cons 040 r)
               (cons 050 a)
               (cons 051 b)
               (cons 010 (trans c 1 z))
               (cons 210 z)
           )
       )
   )
   (princ)
)

 

Link to comment
Share on other sites

  • 7 months later...

Hello there,

Can it get the radius I wrote earlier until I write the new radius.

for example; I'll draw 10 arcs of the same diameter and I'll draw 15 identical arcs of another diameter.

Is it possible not to write the diameter for each of them one by one?

I will be glad if you help

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