how to work in differet Autocad version?

how to work in differet Autocad version?

Anonymous
Not applicable
1,135 Views
7 Replies
Message 1 of 8

how to work in differet Autocad version?

Anonymous
Not applicable

hi everybody. i used C# with activex in autocad2016. how to depeloy to different autocad version?

0 Likes
Accepted solutions (1)
1,136 Views
7 Replies
Replies (7)
Message 2 of 8

_gile
Consultant
Consultant
Accepted solution

Hi,

 

To overcome the COM / ActiveX API versions dependency, a simple way is to use late binding with the 'dynamic' type (requires .NET Framework 4.0 or later).

 

When you think your app is ready to be deployed, make a bakup by copying the whole solution.

In the deployment solution, remove all references to the COM / ActiveX libraries, all using directive to Autodesk.AutoCAD.Interop and Autodesk.AutoCAD.Interop.Common.

Then correct all unknown type errors by replacing COM types with dynamic.

 

e.g. replace:

AcadApplication acadApp = (AcadApplication)Application.AcadApplication;
AcadDocument acDoc = acadApp.ActiveDocument;
AcadModelSpace modelSpace = acDoc.ModelSpace;

with:

dynamic acadApp = Application.AcadApplication;
dynamic acDoc = acadApp.ActiveDocument;
dynamic modelSpace = acDoc.ModelSpace;  

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 8

Anonymous
Not applicable

hi

 

like this one how to replace?

 

AcadMLeader myMLeader;

 

myMLeader.TextRightAttachmentType = AcTextAttachmentType.acAttachmentBottomOfBottom;

 

i replace them like this:

 

dynamic myMLeader;

myMLeader.TextRightAttachmentType = AcTextAttachmentType.acAttachmentBottomOfBottom;

 

but AcTextAttachmentType.acAttachmentBottomOfBottom is error. how to replace by dynamic?

0 Likes
Message 4 of 8

_gile
Consultant
Consultant

Hi,

 

As you certainly know each item in a enumeration (AcTextAttachmentType is a n enum) has an integer value. You can use this integer value instead of the enum item name.

 

You can get the enum integer values (and replace them) before removing COM references with the inellisense (or the object browser):

 

AcTextAttchmentType.png

so, replace:

AcadMLeader yourMLeader;

yourMLeader.TextRightAttachmentType = 
    AcTextAttachmentType.acAttachmentBottomOfBottom;

with:

dynamic yourMLeader;

yourMLeader.TextRightAttachmentType = 6;


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 8

Anonymous
Not applicable
hi,

it is good! i want to use yourMLeader.TextRightAttachmentType = 6; in early binding, because it is easy to transeform to late binding. but it is error. how to do except of yourMLeader.TextRightAttachmentType =AcTextAttachmentType.acAttachmentBottomOfBottom; in early binding?
0 Likes
Message 6 of 8

_gile
Consultant
Consultant

Try with an explicit cast:

 

yourMLeader.TextRightAttachmentType = (AcTextAttachmentType)6;

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 7 of 8

Anonymous
Not applicable
It is ok. Thank you very much!!
0 Likes
Message 8 of 8

Anonymous
Not applicable

Hi,there are another problem when i create region. this work well in early binding.

AcadCircle[] circleObj = new AcadCircle[1];

 

double[] calpt = new double[3];

calpt[0] = 0; calpt[1] = 0; calpt[2] = 0;

circleObj[0] = AcadDoc.ModelSpace.AddCircle(calpt, 5);

// create region

object[] regionObject;

regionObject = (object[])AcadDoc.ModelSpace.AddRegion(circleObj);

 

when i transfer to late binding like this, it is show " Invalid Object Array".

 

dynamic[] circleObj = new dynamic[1];

double[] calpt = new double[3];

calpt[0] = 0; calpt[1] = 0; calpt[2] = 0;

circleObj[0] = AcadDoc.ModelSpace.AddCircle(calpt, 5);

// create region

object[] regionObject;

regionObject = (object[])AcadDoc.ModelSpace.AddRegion(circleObj); //this can't work.

 

How to do it?

0 Likes