.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Cant cast from object to acadarc

4 REPLIES 4
Reply
Message 1 of 5
mpropst
501 Views, 4 Replies

Cant cast from object to acadarc

I get the following error

 

<Unable to cast object of type 'System.Object[]' to type 'Autodesk.AutoCAD.Interop.Common.AcadArc'.>

 

on these lines

 

 Dim oArc3 As AcadArc
 Dim oArc4 As AcadArc
        If oArc1.Radius > oArc2.Radius Then
            oArc3 = DirectCast(oArc1.Offset(BASE_SHELL_OFFSET), AcadArc)
            oArc4 = DirectCast(oArc2.Offset(-BASE_SHELL_OFFSET), AcadArc)

        Else
            oArc3 = DirectCast(oArc1.Offset(-BASE_SHELL_OFFSET), AcadArc)
            oArc4 = DirectCast(oArc2.Offset(BASE_SHELL_OFFSET), AcadArc)
        End If

 

 

oArc1 and oArc2 are acad arcs(obviously) - but the .Offset method sig returns an object not an arc (how weird is that?)

what's the solution with option strict on?

 

4 REPLIES 4
Message 2 of 5
mpropst
in reply to: mpropst

ps without trying to cast to arc i get the following error

 

oArc3 = oArc1.Offset(BASE_SHELL_OFFSET)
oArc4 = oArc2.Offset(-BASE_SHELL_OFFSET)

 

produces the compile error

option strict on disallows implicit conversion from object to acad arc (or something close to that wording)

 

Message 3 of 5
mpropst
in reply to: mpropst

duh! i see it now.

Offset returns array of object, not object

 

Message 4 of 5
norman.yuan
in reply to: mpropst

Well, it only goes as weird as your code goesSmiley Happy

 

The Offset() method returns a variant (in VBA)/object (in .NET), which is and ARRAY of entity generated by the method. You cannot cast an array to an AcadArc/AcadEntity, of course. Depending on the original entity type, the generated entity may not be the same type. Here is the quote from VBA document:

 

<quote>

 

For many curves, the result of this operation will be a single new curve (which may not be of the same type as the original curve). For example, offsetting an ellipse will result in a spline because the result does not fit the equation of an ellipse. In some cases it may be necessary for the offset result to be several curves.

 

</quote>

 

In your case, it is lucky enough, you get a single AcadArc back (i.e. one AcadArc element in the returned array). So, your code should look like this:

 

oArc3 = DirectCast(oArc1.Offset(BASE_SHELL_OFFSET)(0), AcadArc)

 

Norman Yuan

Drive CAD With Code

EESignature

Message 5 of 5
mpropst
in reply to: norman.yuan

yes, thanks

I did finally see that array business.

thanks for your response

mark

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost