inexspected results CONVERTPOLY

Discussion in 'AutoCAD' started by StefVdM, Sep 20, 2004.

  1. StefVdM

    StefVdM Guest

    Hi all,

    Recently I wanted to see what differences there were between the properties of a LWPolyline and a Heavy Polyline.
    First, I created a polyline (using ACAD2000i) the normal way.
    With (vlax-dump-object) I obtained a list of the applicable properties of my polyline. No problem here.

    Then, I used the command "CONVERTPOLY", with the option "heavy", to convert the same polyline to a heavy polyline. Again I used (vlax-dump-object), and this is what I got:

    ; IAcadLWPolyline: AutoCAD Lightweight Polyline Interface
    ; Property values:
    ; Application (RO) = #<VLA-OBJECT IAcadApplication 00a99b84>
    ; Area (RO) = AutoCAD.Application: Invalid class
    ; Closed = AutoCAD.Application: Invalid class
    ; Color = 256
    ; ConstantWidth = AutoCAD.Application: Invalid class
    ; Coordinate = ...Indexed contents not shown...
    ; Coordinates = AutoCAD.Application: Invalid class
    ; Document (RO) = #<VLA-OBJECT IAcadDocument 00fc0f8c>
    ; Elevation = AutoCAD.Application: Invalid class
    ; Handle (RO) = "4849"
    ; HasExtensionDictionary (RO) = 0
    ; Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 17aa24c4>
    ; Layer = "BASIS"
    ; Linetype = "BYLAYER"
    ; LinetypeGeneration = AutoCAD.Application: Invalid class
    ; LinetypeScale = 1.0
    ; Lineweight = -1
    ; Normal = AutoCAD.Application: Invalid class
    ; ObjectID (RO) = 1074238280
    ; ObjectName (RO) = "AcDb2dPolyline"
    ; OwnerID (RO) = 1074203840
    ; PlotStyleName = "ByLayer"
    ; Thickness = AutoCAD.Application: Invalid class
    ; Visible = -1
    T

    When I convert the same polyline again (to "light"), no problem again. What went wrong here? Did I misunderstand the use of the command? Or am I missing something in regard to the difference between the "heavy" and the "light" version of polylines?

    Stef
     
    StefVdM, Sep 20, 2004
    #1
  2. StefVdM

    BillZ Guest

    I get the same problem with R2005.


    Bill
     
    BillZ, Sep 20, 2004
    #2
  3. Hi Stef,

    I would call it a bug. It happens when you create a link to an object
    (in this case you create it using vlax-dump-object), then convert
    the object to another type (in this case from heavy to light polyline
    or vice versa). Because you did not release the object, the object
    didn't realise that its type has changed and therefore all the
    invalid class notices.
    If you assign the object to a variable and release it (with vlax-release-object)
    before converting this will not happen.
    This is why it is very important always to release the objects you use,
    else you will get an exception if you want for example obtain the area
    of the poyline.

    BTW: Converting an object type can also happen when using the command trim:
    Circle->arc, xline->ray->line

    Stephan
     
    Stephan Koster, Sep 20, 2004
    #3
  4. StefVdM

    StefVdM Guest

    Stephan,

    I tried the following:

    1- select the polyline and catch the selected polyline in the variable "object". ;;;(vla-getentity util 'object 'pp);;;

    2- dump the object -> no problem

    3- release the object ;;;(vlax-release-object object);;; I get return value "1", so I guess the releasing worked OK.

    4- (vlax-dump-object) again (just to check). Return value: ; "Object is not connected".

    5- convert to heavy polyline using "convertpoly" (from the command line). I get return value "1 polyline objects converted", so everything's fine.

    6- select the converted polyline again, catching it in the same variable "object".

    7- dump the object... same result as in my original post!

    Were did I go wrong?
    Where can I find more explanation about how, why and when releasing objects?

    Thanks,

    Stef
     
    StefVdM, Sep 20, 2004
    #4
  5. StefVdM

    StefVdM Guest

    Something more:

    When I try to get the properties of the converted polyline (properties toolbar), there's no geometry info available! Although the entity is recognised as being a polyline, with the appropriate layer, linetype, etc. But no vertices, width...

    The command "list" on the contrary does give all the info.

    But maybe it's not worth going further into detail with this. I just wanted to convert a LWpolyline to a heavy one to see what the differences in properties were. So as to be able to detect the difference through programming. And this is what I stumbled upon.

    Stef
     
    StefVdM, Sep 20, 2004
    #5
  6. If you get the return value 1 then it means that there is one link left.
    If the object is fully released you will get 0 as return value.

    Try this:
    1. draw a polyline
    2. select it and catch it in the variable o:
    (setq o(vlax-ename->vla-object(car(entsel))))
    3. dump it
    4. release o
    (vlax-release-object 0) -> return value should be 0
    5. convert the polyline
    6. redo steps 2 and 3
    -> everything should work fine

    If you need more informations about releasing objects the only place
    that I know where you can get it is this group.

    Stephan
     
    Stephan Koster, Sep 20, 2004
    #6
  7. 4. release o
    Oops, this should be of course:
    (vlax-release-object o) -> return value should be 0
     
    Stephan Koster, Sep 20, 2004
    #7
  8. StefVdM

    Doug Broad Guest

    If you release and object and the return value is 1, then it indicates
    that the object still has a reference to it and therefore will cause problems.

    Try (gc) to clear the references. Otherwise you will have to figure out
    where the other reference came from. Sometimes a proper cleanup
    is not done.

    You can't use the same symbol to release the object twice.



    ;;;(vla-getentity util 'object 'pp);;;
    value "1 polyline objects converted", so everything's fine.
     
    Doug Broad, Sep 20, 2004
    #8
  9. This is the same problem that can be seen when you BREAK
    a circle, which changes it to an ARC.

    The problem is that the existing COM wrapper is not released,
    and it is type-specific. Hence, the heavy polyline still has a
    COM wrapper for a lightweight polyline.

    While others here have suggested that you use (vlax-release-object)
    to release outstanding references, the fact is that you cannot
    assume that there are no other outstanding references to the object
    that have nothing to do with your code, and hence, there is no
    guarantee that simply releasing your own reference to the object
    is going to release all references, which is necessary for the COM
    wrapper to be destroyed, which allows you to recreate a new one
    of the correct type.

    I wouldn't call this a 'bug' per se, it is more a design flaw.
     
    Tony Tanzillo, Sep 20, 2004
    #9
  10. StefVdM

    StefVdM Guest

    Hi,

    Lovely to know there are so many people in the world that know so much..

    What I noticed:

    - If I use (setq o (vlax-ename->vla-object (car (entsel)))), like Stephan suggested, I can dump, release, convert and dump again just fine! Release gives a return value 0.

    - If I use (vla-getEntity util 'o 'pp), like I did before, the release always gives me a return value of 1!

    Is the vla-getEntity doing something that entsel doesn't do? Apparently using vla-getEntity is itself creating some reference to the object. Even (gc) doesn't seem to make a difference.

    So, basically, my problem is solved, and we're just left with a bug or design-flaw. Thank you all for your help! I've become a lot wiser again.

    Stef
     
    StefVdM, Sep 21, 2004
    #10
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.