vlax-curve-getpointatparam failing

vlax-curve-getpointatparam failing

john.uhden
Mentor Mentor
2,363 Views
11 Replies
Message 1 of 12

vlax-curve-getpointatparam failing

john.uhden
Mentor
Mentor

As you may know, I have been trying to create @braudpat's function for adding vertices at every midpoint of a polyline's segments.

It is failing occasionally when trying to get the midpoint of the last segment.

Does anyone know why?  This is not a quiz.  I haven't a clue.

 

Try this test on any, in fact many, poylines (LW, heavy, 3D, closed, open) and see what you get.

In some situations, the midpoint of the last segment is returned as nil.

 

 

(defun c:test ()
  (and
    (setq e (car (entsel)))
    (setq obj (vlax-ename->vla-object e))
    (setq objname (vlax-get obj 'ObjectName))
    (or
      (wcmatch objname "*olyline")
      (alert "Object selected is not a polyline.")
    )
    (princ "\nClosed: ")(princ (vlax-get obj 'Closed))
    (setq end (vlax-curve-getendparam obj))
    (princ "    Midpoint of last segment: ")
    (princ (setq p (vlax-curve-getpointatparam obj (- end 0.5))))
  )
  (princ)
)

 

John F. Uhden

0 Likes
Accepted solutions (3)
2,364 Views
11 Replies
Replies (11)
Message 2 of 12

dlanorh
Advisor
Advisor
Accepted solution
I can't see anything out of place with the code. Limited testing couldn't reproduce the error in 2012.

Things to consider (ramblings) :

You can't remove the last segment on a closed polyline unless you have drawn the polyline back to the start point before closing it (using pedit)

Can you get the correct point via (vlax-curve-getpointatdist obj (vlax-curve-getdistatparam obj)) ?

Does (vlax-curve-isclosed obj) return the same as (vlax-get obj 'closed)?

(vlax-curve-isperiodic obj)

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

0 Likes
Message 3 of 12

john.uhden
Mentor
Mentor
No, there's nothing wrong with my code. It's the results that are
bothersome. I'll have to try one of your ramblings.

The only thing I can think of is if the last vertex were drawn to the first
vertex and then closed, which I think would leave the endpoint and the (1-
endpoint) at the same point, leaving zero distance between them. But I am
pretty sure I had not created such a test condition.

John F. Uhden

0 Likes
Message 4 of 12

john.uhden
Mentor
Mentor

Well, appaently you can't use (vlax-get obj 'Closed) on a spline curve polyline...

(vlax-get object 'closed) ; error: AutoCAD.Application: Invalid class.

It's not that I really need to know if the polyline is closed; it's just that I have been suspecting that the pointatparam failure may be related to the closure.

 

Anyway, this works better to get to the actual test.  Many thanks.

(defun c:test ()
  (and
    (setq e (car (entsel)))
    (setq obj (vlax-ename->vla-object e))
    (setq objname (vlax-get obj 'ObjectName))
    (or
      (wcmatch objname "*olyline")
      (alert "Object selected is not a polyline.")
    )
    (princ "\nClosed: ")(or (princ (vlax-curve-isclosed obj)) 1)
    (setq end (vlax-curve-getendparam obj))
    (princ "    Midpoint of last segment: ")
    (princ (setq p (vlax-curve-getpointatparam obj (- end 0.5))))
  )
  (princ)
)

And, no, I haven't run into any failures here at work.  Maybe my laptop at home is possessed.

John F. Uhden

0 Likes
Message 5 of 12

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:

Well, appaently you can't use (vlax-get obj 'Closed) on ....


 

As for that particular issue, if it's of any help, you can find that out without resorting to the content of the 'Closed VLA Property, but more directly:

 

(vlax-curve-isClosed obj)

 

which returns T if it's closed, nil if not.  It also works with an entity name rather than a VLA object.

Kent Cooper, AIA
0 Likes
Message 6 of 12

john.uhden
Mentor
Mentor

Thanks, Kent.  I think that's what @dlanorh was suggesting.

John F. Uhden

0 Likes
Message 7 of 12

dlanorh
Advisor
Advisor

@john.uhden wrote:

Anyway, this works better to get to the actual test.  Many thanks.And, no, I haven't run into any failures here at work.  Maybe my laptop at home is possessed


I doubt it, that would only happen tomorrow. Robot tongue

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

0 Likes
Message 8 of 12

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:

Thanks, Kent.  I think that's what @dlanorh was suggesting.


 

I hadn't noticed their mention of that.  The difference is that (vlax-curve-isClosed) returns either T or nil, whereas the VLA Property is either 0 or -1.  So with 'e' as the entity name, there's a savings in having only to test for:

 

(if (vlax-curve-isClosed e) ...

 

rather than to make it a VLA Object and then check a Property of that:

 

(setq obj (vlax-ename->vla-object e))

(if (= (vlax-get obj 'closed) -1) ...

 

[If you need to convert it to a VLA Object for other purposes anyway, the "savings" is reduced to only a few characters.  But you don't need to make that conversion if it's only for getting parameters and/or points with (vlax-curve...) functions, since they can work with entity names as well as with VLA Objects.]

Kent Cooper, AIA
0 Likes
Message 9 of 12

john.uhden
Mentor
Mentor
Thank you for reminding me of that again. My code later uses (vlax-put obj
'Coordinates) and (vla-setbulge obj), so the vla-object thingy is not a
waste,
Saving code really doesn't bother me. You should see some of my
paleolithic creations that still work.
Now I've been thinking that the phenomenon happens only after adding
vertices per @braudpat's request. I will try adding a vla-update to see if
that relieves the symptoms.

John F. Uhden

0 Likes
Message 10 of 12

Kent1Cooper
Consultant
Consultant
Accepted solution

@john.uhden wrote:
…. I've been thinking that the phenomenon happens only after adding
vertices per @braudpat's request. …..

 

… which makes me wonder -- could it make any difference if you add the vertex in the middle of the last segment first, and work your way from there toward the beginning?  I haven't studied your code to consider whether that's likely, but it may be worth an experiment.

Kent Cooper, AIA
0 Likes
Message 11 of 12

dbroad
Mentor
Mentor
Accepted solution

I'm sure that everyone participating on this thread is aware of the potential problems of assuming what curve parameters mean (per TT and OW).  For the benefit of others, I post a link to Owen's blog on the matter.

 

QuirkyPolyline: exposing foolish programmers

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 12 of 12

john.uhden
Mentor
Mentor

Hi, Doug.

Since I would probably trust Owen with my life (even severely depreciated), I must try the distance approach instead of the parameter approach.  Maybe tonight.

John F. Uhden

0 Likes