Jump to content

Smallest radius in a closed polyline


Mr Bojangles

Recommended Posts

Hi Guys

 

I'm.currently working on a routine, and I've hit a wall..

I'm only a novice lisper and also I can only code with Autolisp, although I've incorporated Visual lisp from various sources into my routines. 

This time though I'm stuck.

I can't find what I need with the search function (or Google )and I'm hoping that's because I'm not using the right parameters rather than it not being possible.

What I'm trying or wanting to do in this part of my routine is, find the smallest radius that is on a closed polyline and put that value into a variable, so that it can be used in another part of my routine.

My routine layout is as follows

I would be using a selection set to get the correct polyline (using a layername filter).

Then I want to find the smallest radius on that polyline and put it in a variable (more than likely called "smrad".

Then I would be comparing that variable with another.

If it's okay then the routine would continue to do more, else it would pop up a message and end.

 

Hope someone can help me

 

Link to comment
Share on other sites

Thanks for the info mhupp

I'll take a look at that today

 

Link to comment
Share on other sites

A start with this?

(defun def_bulg_pl (ls lb / l_rad)
  (setq ls (append ls (list (car ls))))
  (while (cadr ls)
    (if (zerop (car lb))
      (setq l_rad (cons (car lb) l_rad))
      (setq l_rad (cons (/ (distance (car ls) (cadr ls)) (sin (* 2.0 (atan (abs (car lb))))) 2.0) l_rad))
    )
    (setq ls (cdr ls) lb (cdr lb))
  )
  l_rad
)
(defun c:test ( / sspl typent lst l_bulg e_next dxf_next rad)
  (while (null (setq sspl (ssget "_+.:E:S" '((0 . "*POLYLINE") (-4 . "<AND") (-4 . "&") (70 . 1) (-4 . "<NOT") (-4 . "&") (70 . 124) (-4 . "NOT>") (-4 . "AND>")))))
    (princ "\nInvalid object")
  )
  (setq typent (cdr (assoc 0 (setq dxf_ent (entget (setq ent (ssname sspl 0)))))))
  (cond
    ((eq typent "LWPOLYLINE")
      (setq
        lst (mapcar '(lambda (x) (trans x ent 1)) (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) dxf_ent)))
        l_bulg (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 42)) dxf_ent))
        lst (def_bulg_pl lst l_bulg)
      )
    )
    ((eq typent "POLYLINE")
      (setq e_next (entnext ent))
      (while (= "VERTEX" (cdr (assoc 0 (setq dxf_next (entget e_next)))))
        (if (zerop (boole 1 223 (cdr (assoc 70 dxf_next))))
          (setq
            lst (cons (trans (cdr (assoc 10 dxf_next)) ent 1) lst)
            l_bulg (cons (cdr (assoc 42 dxf_next)) l_bulg)
          )
        )
        (setq e_next (entnext e_next))
      )
      (setq
        lst (reverse lst)
        l_bulg (reverse l_bulg)
        lst (def_bulg_pl lst l_bulg)
      )
    )
  )
  (if (setq rad (car (vl-remove 0.0 (vl-sort lst '<))))
    (princ (strcat "\nMinor radius found " (rtos rad 2)))
    (princ "\nNo radius found in this polyline")
  )
  (prin1)
)

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Wow, yes

That works perfectly. 

With your permission I would like to use that as part of my larger routine.

 

I'm still reading up on the bulge information, I get some of it, some not so much, hopefully reading through your routine will help me understand better.. I also know I really should be getting into Vlisp more.

Link to comment
Share on other sites

I like this thread.. Good question, I too have had to do this and great answers as usual by the talent on this website, my solution was a lot more long winded than tsukys elegant work.

  • Agree 1
Link to comment
Share on other sites

@Mr Bojangles

Quote

With your permission I would like to use that as part of my larger routine.

No problem, if I put the code in plain text, it's because I'm sharing it otherwise I would compile the code if I wanted to keep control of it.😉

  • Like 1
Link to comment
Share on other sites

Thank you Tsuky

And thank you to everyone else for your help and comments.

Link to comment
Share on other sites

@mhupp

On 3/8/2024 at 1:30 AM, mhupp said:

I just saw your name and am cracking up.

I don't know if this is aimed at me.
If so, what I can say:
I am a retired Frenchman
I introduce myself:
Under Bonuscad in the French forums
Under CADaSchtroumpf on the AutoDesk forums
Under Bruno.Valsecchi on the AUGI forum
And Tsuky here (that's my cat's name: moon in Japanese)

Link to comment
Share on other sites

7 minutes ago, Tsuky said:

@mhupp

I don't know if this is aimed at me.
If so, what I can say:
I am a retired Frenchman
I introduce myself:
Under Bonuscad in the French forums
Under CADaSchtroumpf on the AutoDesk forums
Under Bruno.Valsecchi on the AUGI forum
And Tsuky here (that's my cat's name: moon in Japanese)

@Tsuky I think mhupp was referring to the OP's screen name of "Mr Bojangles" 😃

  • Agree 1
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...