Hole Feature and shared Sketch. VB and C# disagree

Hole Feature and shared Sketch. VB and C# disagree

mirkomaga
Contributor Contributor
345 Views
2 Replies
Message 1 of 3

Hole Feature and shared Sketch. VB and C# disagree

mirkomaga
Contributor
Contributor

Hello,
I trying to get Sketch Definition from Hole Feature.

Considering that it is the same document:

 

VB: 

mirkomaga_0-1650523286064.png

 

 

Addin c#:

mirkomaga_1-1650523390172.png

 

 

As you can well see: in the second image the sketch throw me an exception that is not there in the first one.

 

This is Model, anyone have the same problem?

mirkomaga_2-1650523529902.png

 

0 Likes
Accepted solutions (1)
346 Views
2 Replies
Replies (2)
Message 2 of 3

Zach.Stauffer
Advocate
Advocate

Can you share VB and C# code?

0 Likes
Message 3 of 3

jatindevaiya08
Contributor
Contributor
Accepted solution

@mirkomaga 

I have created C# code for the same and it's working fine for me. See attached images.

Test_4.png

SketchName_1.png


Here is the C# code. It's console Application code. And note that Inventor application as well as Part is open when you test it.

 

 

Inventor.Application inventorApplication = (Inventor.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application");

PartDocument partDocument = (PartDocument)inventorApplication.ActiveDocument;
PartComponentDefinition partComponentDefinition =partDocument.ComponentDefinition;

foreach (PartFeature partfeature in partComponentDefinition.Features)
{
  if (partfeature.Type == ObjectTypeEnum.kHoleFeatureObject)
  {
    HoleFeature holeFeature = (HoleFeature)partfeature;
    Console.WriteLine(holeFeature.Sketch.Name);
   }
}

 

 


Regards,
Jatin Devaiya

Accept it as solution.

Regards,
Jatin Devaiya

If a response answers your question, please use ACCEPT SOLUTION to assist other users later.


Also be generous with Likes! Thank you and enjoy!
0 Likes