Arc report

Arc report

sean.keohane
Advocate Advocate
752 Views
8 Replies
Message 1 of 9

Arc report

sean.keohane
Advocate
Advocate

Hi,

I have pieced together this lisp which is intended to report 4 dimensions.

E = radius

A=arc length

B=Chord

C=Rise.

The E, A, and B are reporting for me but only when I exclude the C equations which I obviously haven't got right.

This is intended strictly for arc's to double check schedules of reinforcement shape code 67. (British standard code for a radius bar).

It reports to screen but I hoped I could get it to insert a text near the selected arc but I got bogged down with the C dim issue.

Can someone more knowledgeable than I,take a look and set me straight.

Much appreciated

Regards

Sean

0 Likes
Accepted solutions (2)
753 Views
8 Replies
Replies (8)
Message 2 of 9

Kent1Cooper
Consultant
Consultant

Very quick perusal -- perhaps make this change?

....

  (setq p4 (vlax-curve-getpointatdist x (* A 0.5))) ; midpoint of arc

....

Kent Cooper, AIA
0 Likes
Message 3 of 9

doni49
Mentor
Mentor

Kent is very good at this so there's a good chance he's solved it.  But in case he hasn't, I'll ask this:  can you give us a layman's version of how C is supposed to be calculated?  Write it as though you're a teacher and you're showing the formula to your students for the first time.

 

Just C = ................. (the algebraic formula).



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

0 Likes
Message 4 of 9

phanaem
Collaborator
Collaborator
Accepted solution

The problem in C formula is that A is a string, and cannot be used.

Maybe this:

(defun c:test (/ ARC A B C E)

  (vl-load-com)

  (cond
    (*activeDoc*)

    ((setq *activeDoc* (vla-get-activedocument (vlax-get-acad-object)))
    )
  )

  (if (setq ARC (ssget ":S:E" '((0 . "ARC"))))

    (progn

      (vlax-for x (setq ARC (vla-get-activeselectionset *activeDoc*))
        
        (setq E (vla-get-radius x))
        
        (setq A (vla-get-arclength x))
        
        (setq B (distance
                  (vlax-curve-getstartpoint x)
                  (vlax-curve-getendpoint x)
                )
        )
        
        (setq C (* E (- 1 (cos (/ A E 2.0)))))
        
        (textpage)

        (prompt "\nShape code 67 dimensions: ")

        (prompt "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ")

        (prompt (strcat "\n\t\tDim E >> " (rtos E 2 2) " mm"))
        
        (prompt (strcat "\n\t\tDim A >> " (rtos A 2 2) " mm"))
        
        (prompt (strcat "\n\t\tDim B >> " (rtos B 2 2) " mm"))
        
        (prompt (strcat "\n\t\tDim C >> " (rtos C 2 2) " mm"))

        (prompt "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ")

        (terpri)
      )
      (vla-delete arc)
    )
  )

  (princ)
)
0 Likes
Message 5 of 9

sean.keohane
Advocate
Advocate

Hi Kent,

I tried your suggestion but no joy. I think I'm doing something else wrong, as well. I appreciate your input.

Regards

Sean

0 Likes
Message 6 of 9

sean.keohane
Advocate
Advocate

Hi Doni,

I'm not a mathematician but what I'm attempting to achieve with the code at Setq C is find the distance between the midpoint of the chord to the midpoint of the arc. I think this is called the sagitta in maths speak. The equation s = r - \sqrt(r^2-l^2), where s=sagitta, r=radius of arc and l=chord/2.

I hope this is correct.

Thanks for your reply,

Regards

Sean

0 Likes
Message 7 of 9

sean.keohane
Advocate
Advocate

Hi Phanaem,

I tried your code and it works. Thank you for helping me out. You made it less complicated which, for me, is always a good thing! I'm going to research your code to understand how it works now.

Regards

Sean

0 Likes
Message 8 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

Further possible streamlinings....

 

If it's letting you select only one Arc, it hardly seems worth using a function such as (vlax-for) that's made for stepping through multiple objects, and the whole active-selection-set and active-document stuff associated with that.  And you can combine things so that it involves only one (setq) function after the initial Arc selection, and only one (prompt) function.  [I also prefer to pull (vl-load-com) outside of command definitions, because you don't need to run it every time you run the command, but only once, when you load it.]  I think this is equivalent:

 

(defun c:test2 (/ arc A B C E)
  (if (setq arc (ssget ":S:E" '((0 . "ARC"))))
    (progn
      (setq
        arc (vlax-ename->vla-object (ssname arc 0))
        E (vla-get-radius arc)
        A (vla-get-arclength arc)
        B (distance (vlax-curve-getstartpoint arc) (vlax-curve-getendpoint arc))
        C (* E (- 1 (cos (/ A E 2.0))))
      ); setq
      (textpage)
      (prompt
        (strcat
          "\nShape code 67 dimensions: "
          "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "
          "\n\t\tDim E >> " (rtos E 2 2) " mm"
          "\n\t\tDim A >> " (rtos A 2 2) " mm"
          "\n\t\tDim B >> " (rtos B 2 2) " mm"
          "\n\t\tDim C >> " (rtos C 2 2) " mm"
          "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "
        ); strcat
      ); prompt
      (terpri)
      (vla-delete arc); [do you really want to do this?]
    ); progn
  ); if
  (princ)
); defun
(vl-load-com)
Kent Cooper, AIA
Message 9 of 9

sean.keohane
Advocate
Advocate

Hi Kent,

I was really making things difficult, wasn't I. Thanks for explaination, I always have an uphill battle getting my head around lisp. Alot of trial and error before I call in the troops. Although, the odd time I get something working without help, gives me a sense of satisfaction. 

I appreciate your time,

Regards

Sean

 

0 Likes