[Inventor API] Problem with Thicken Command

[Inventor API] Problem with Thicken Command

Khoa_NguyenDang
Advocate Advocate
1,765 Views
10 Replies
Message 1 of 11

[Inventor API] Problem with Thicken Command

Khoa_NguyenDang
Advocate
Advocate

Hi all 

 

I am facing a problem with Thicken Command 

Here is the code I use. It just normal is for each face of Solid [1], I will create the Thicken Feature. But when it run I just can create the thicken for the first Face, for the Second face of solid, it will be an error to access that face for Thicken Feature. So it means the problem is can not define the face after the first Thicken, I also tried to get the InternalName of Face after the first Thicken, the same error show.

 

SurfaceBody sb = partDef.SurfaceBodies[1];
sb.Name = "Panel";

 

foreach (Face face in sb. Faces)
{

FaceCollection FacesCol = default(FaceCollection);
FacesCol = _invApp.TransientObjects.CreateFaceCollection();
ThickenFeature oThickFeat = default(ThickenFeature);
FacesCol.Clear();
FacesCol.Add(face);
try
{
oThickFeat = partDef.Features.ThickenFeatures.Add(FacesCol, "1", PartFeatureExtentDirectionEnum.kNegativeExtentDirection, PartFeatureOperationEnum.kNewBodyOperation, false);
}
catch
{

MessageBox.Show("Error");
}

}

The error like the picture I attached

Khoa_NguyenDang_0-1619498463459.png

Have anybody met the same problem before, if someone knows it, please help me. Thank you so much.

0 Likes
1,766 Views
10 Replies
Replies (10)
Message 2 of 11

Ralf_Krieg
Advisor
Advisor

Hello

 

Why do you create the thicken feature for each face itself? You can add all faces in one FaceCollection and call the thicken feature with this Collection.

In your way, it is possible that the first thicken feature modifies the model so that face2 in the surfacebody.faces collection is not longer existing.

I didn't test it, but you can try loop after each thicken feature for 1 face through the surfacebody.faces collection from start and check for each face if it's createdbefeature.type property is kthickenfeatureobject, else call thickenfeature for this face.


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 3 of 11

dutt.thakar
Collaborator
Collaborator

@Khoa_NguyenDang 

 

Can you upload your part in which you are trying to use the code?

 

 

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes
Message 4 of 11

Khoa_NguyenDang
Advocate
Advocate

Just a normal Part Rectangle file @dutt.thakar 

Khoa_NguyenDang_0-1619518121418.png

 

0 Likes
Message 5 of 11

Khoa_NguyenDang
Advocate
Advocate

HI @Ralf_Krieg 

For my code, it will recreate a FaceCol for each Face

I also create a FaceCol before Loop, but the problem still have problem

0 Likes
Message 6 of 11

dutt.thakar
Collaborator
Collaborator

@Khoa_NguyenDang 

 

Can you try the below code and see if that helps? I have just removed the automatic face chains in the code and tested the code on a rectangular box.

 

 

SurfaceBody sb = partDef.SurfaceBodies[1];
sb.Name = "Panel";

 

foreach (Face face in sb. Faces)
{

FaceCollection FacesCol = default(FaceCollection);
FacesCol = _invApp.TransientObjects.CreateFaceCollection();
ThickenFeature oThickFeat = default(ThickenFeature);
FacesCol.Clear();
FacesCol.Add(face);
try
{
oThickFeat = partDef.Features.ThickenFeatures.Add(FacesCol, "1", PartFeatureExtentDirectionEnum.kNegativeExtentDirection, PartFeatureOperationEnum.kNewBodyOperation);
}
catch
{

MessageBox.Show("Error");
}

}

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes
Message 7 of 11

Ralf_Krieg
Advisor
Advisor

Hello

 

I think the problem is, that the first thicken feature creates new faces and invalidates the faces collection. You have to collect all the faces you need in a new collection and travers this one. An example in VBA.

 

Private Sub Thicken()

Dim oApp As Inventor.Application
Set oApp = ThisApplication

Dim oPartDoc As PartDocument
Set oPartDoc = oApp.ActiveDocument

Dim oCompDef As PartComponentDefinition
Set oCompDef = oPartDoc.ComponentDefinition

Dim oSB As SurfaceBody
Set oSB = oCompDef.SurfaceBodies.Item(1)

oSB.Name = "Panel"

Dim oFacesCol As FaceCollection
Set oFacesCol = oApp.TransientObjects.CreateFaceCollection

Dim oFace As Face
For Each oFace In oSB.Faces
    Call oFacesCol.Add(oFace)
Next

Dim oThickFeat As ThickenFeature

For Each oFace In oFacesCol
    Dim oFaceCol As FaceCollection
    Set oFaceCol = oApp.TransientObjects.CreateFaceCollection
    Call oFaceCol.Add(oFace)
    Set oThickFeat = oCompDef.Features.ThickenFeatures.Add(oFaceCol, "1", PartFeatureExtentDirectionEnum.kNegativeExtentDirection, PartFeatureOperationEnum.kNewBodyOperation, False)
Next

End Sub

R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 8 of 11

Khoa_NguyenDang
Advocate
Advocate

It also a idead, Le's i tried it

0 Likes
Message 9 of 11

Khoa_NguyenDang
Advocate
Advocate

thank for your idead, let i try it 

0 Likes
Message 10 of 11

Khoa_NguyenDang
Advocate
Advocate

Hi @Ralf_Krieg 

 

The same problem although I tried your solution 

Khoa_NguyenDang_0-1620657150529.png

My code

FaceCollection FacesCol = _invApp.TransientObjects.CreateFaceCollection();

foreach (Face face in VNKcol)
{
FacesCol.Add(face);
}

ThickenFeature oThickFeat = default(ThickenFeature);

foreach(Face f in FacesCol)
{
FaceCollection FaceCol = _invApp.TransientObjects.CreateFaceCollection();
FaceCol.Add(f);
oThickFeat = partDef.Features.ThickenFeatures.Add(FaceCol, "1mm", PartFeatureExtentDirectionEnum.kNegativeExtentDirection, PartFeatureOperationEnum.kNewBodyOperation, true);
}

Do you have any other method

 

0 Likes
Message 11 of 11

Ralf_Krieg
Advisor
Advisor

Hello

 

Sorry, no other method so far.

Does this happen also with the simple rectangular part you posted above? Is the model up to date at the time you try to create the features? Can you try to call a document.update right before you create the first face collection?

I've tried this with the VBA code multiple times without any error.


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes