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

Help with CAO GetLinks() function

1 REPLY 1
Reply
Message 1 of 2
wesbird
668 Views, 1 Reply

Help with CAO GetLinks() function

Hi,
I got a problem to run CAO GetLinks in C# and get a error message:
"The parameter is incorrect."
and I found a solution from ObjectARX group
http://discussion.autodesk.com/thread.jspa?messageID=398629
but I am not good at ObjectARX, can someone help me fix this problem?
here is my code:
//
// Remove Link
public static void RemoveLink(ObjectId objId, string LT_name, string KeyValue)
{
//
CAO.DbConnect odbConnect;
Autodesk.AutoCAD.Interop.AcadApplication acadApp;
Autodesk.AutoCAD.Interop.AcadDocument acadDoc;

Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
acadApp = (Autodesk.AutoCAD.Interop.AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
acadDoc = acadApp.ActiveDocument;

// if (odbConnect == null )
// {
try
{
if (acadApp != null)
{
odbConnect = (CAO.DbConnect)acadApp.GetInterfaceObject("CAO.DbConnect.16");
CAO.LinkTemplates LTs = odbConnect.GetLinkTemplates(acadDoc);

CAO.LinkTemplate LT;
try
{
LT = LTs.Item(LT_name);
}
catch(System.Exception caught)
{
ed.WriteMessage(caught.ToString());
return;
}

long[] ObjIds = new long[1];
ObjIds[0] = objId.OldId;

// CAO.Links Links = odbConnect.GetLinks(LT, ObjIds, (int)CAO.LinkType.kEntityLinkType,acadDoc);
CAO.Links Links = odbConnect.GetLinks(LT, ObjIds, 2,acadDoc);

foreach (CAO.Link link in Links)
{
CAO.KeyValues kvs = link.KeyValues;
foreach (CAO.KeyValue kv in kvs)
{
if ((string)kv.Value == KeyValue)link.Delete();
}
}
}
}
catch (System.Exception caught)
{
ed.WriteMessage(caught.Message.ToString());
}
// }


}


Wes Message was edited by: weslleywang
Windows 10 64 bit, AutoCAD (ACA, Map) 2023
1 REPLY 1
Message 2 of 2
Daniel.Du
in reply to: wesbird

you need to pass parameter with object type,  try following code snippet, pay attention to the type converting:

 

CAO.Links Links = odbConnect.GetLinks(LT,(object) ObjIds, 2,acadDoc);



Daniel Du
Developer Technical Services
Autodesk Developer Network

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