API Extrude Feature all closed Sketches

API Extrude Feature all closed Sketches

Anonymous
Not applicable
1,548 Views
6 Replies
Message 1 of 7

API Extrude Feature all closed Sketches

Anonymous
Not applicable

Hello Community,

 

I have some serrious trouble with a rule,

I need to extrude all closed loops in a specific sketch.

 

This problem have been well solved by the great Curtis in his Inventor trenches Blog page:

 

http://inventortrenches.blogspot.co.at/2012/03/ilogic-to-select-all-of-closed-profiles.html?m=1

 

But i need something similar but different!!!!

 

I don´t like to create a new extrusion.

I like to add the profiles from an specific sketch to an existing extrusion.

 

My code is attached below, I think I m very close to the solution but at this point my programming skills come to an end.

 

I have serious troubles with the 

 

SyntaxEditor Code Snippet

Dim oExtrude As ExtrudeFeatures
oExtrude = ThisApplication.ActiveDocument.ComponentDefinition.Extrusion

......Comand.......but I m not shure if this is the only thing whats wrong

 

If i know how i can specify the sketch and the extrusion , I can easy manage to copy them to other bodys.

May there is an "for every sketch" solution? 

 

 

Any help in this case would be great!!!---------Kudo!

 

Excuse my texting, I m not a native

 

Thanks

 

Simon

 

 Full Code:

 

SyntaxEditor Code Snippet

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

Dim oCompDef As PartComponentDefinition
oCompDef = oPartDoc.ComponentDefinition

Dim oSketches As PlanarSketches
oSketches = ThisApplication.ActiveDocument.ComponentDefinition.Sketches

Dim oSketch As PlanarSketch
oSketch = oSketches.Item("CUT_SW1_S")

Dim oProfile As Profile
oProfile = oSketch.Profiles.AddForSolid


' Create an extrusion
Dim oExtrude As ExtrudeFeatures
oExtrude = ThisApplication.ActiveDocument.ComponentDefinition.Extrusion

oExtrude = oExtrude.Item("CUT_SW1_S")
oExtrude = oCompDef.ExtrudeDefinition.Profile(oProfile)


iLogicVb.UpdateWhenDone = True

 

 

0 Likes
Accepted solutions (1)
1,549 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

Hello,

 

I found the solution by my own. the correct line to add all Profiles to an existing sketch is:

 

SyntaxEditor Code Snippet

Dim oExtrudeWC1 As ExtrudeFeature = Feature.InventorFeature("CUT_SW1")
oExtrudeWC1.Profile = oProfileWC1

 

My code works fine, I can add as many circles/closed lines ect. I want.

But if I delete one of these circles my Model crashes and i cant fix it by firing the rule.

 

The only way to heal it, is to activate the extrusion feature dialog box, by hand, the model instantly gets all profiles.

 

So if i add Profiles-it work

If i delete Profiles-crash

 

How can I fix this in my rule?

 

Any help would be great!!!

 

I tried to launch the Feature.Edit comand in my rule but this doesent work too

 

Code and new model attached

 

Thanks

 

Simon

 

 

SyntaxEditor Code Snippet

'--------------------------------------------------SW1----------------------------------------'.ActiveDocument

Dim oPartDoc As PartDocument
oPartDoc = ThisDoc.Document

Dim oCompDef As PartComponentDefinition
oCompDef = oPartDoc.ComponentDefinition

Dim oSketches As PlanarSketches
oSketches = ThisDoc.Document.ComponentDefinition.Sketches

'-------------------------------SW1---CUT1---------------------------------

Dim oSketchWC1 As PlanarSketch
oSketchWC1 = oSketches.Item("CUT_SW1_S")

Dim oProfileWC1 As Profile
oProfileWC1 =oSketchWC1.Profiles.AddForSolid

Dim oExtrudeWC1 As ExtrudeFeature = Feature.InventorFeature("CUT_SW1")
oExtrudeWC1.Profile = oProfileWC1

''------------------------SW1---CUT2-------------------------

Dim oSketchWC2 As PlanarSketch
oSketchWC2 = oSketches.Item("CUT2_SW1_S")

Dim oProfileWC2 As Profile
oProfileWC2 =oSketchWC2.Profiles.AddForSolid(True)

Dim oExtrudeWC2 As ExtrudeFeature = Feature.InventorFeature("CUT2_SW1")
oExtrudeWC2.Profile = oProfileWC2


RuleParametersOutput()
InventorVb.DocumentUpdate()

 

 

 

 

0 Likes
Message 3 of 7

wayne.brill
Collaborator
Collaborator

Hi Simon,

 

I downloaded your ipt and ran the rule. I am not sure what you are doing to cause the crash. Please provide the code that is crashing or the manual steps I need to take to recreate the crash.

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 4 of 7

Anonymous
Not applicable

Hello Wayne,

 

Thanks for your support!

 

If i add Profiles (in the sketch) to the extrusion called "CUT_SW1" or "CUT2_SW1" and then run the rule, every profile is added to the extrusion.

 

If i delete one ore more profiles from the sketch, it crashes.

 

The strange thing is, if i delete a profile in the first extrusion called "CUT_SW1" an error occure, but i can update by running the rule.

If i delete a profile of the second set, called "CUT2_SW1" and then run the rule:

 

Unbekannter Fehler (Ausnahme von HRESULT: 0x80004005 (E_FAIL))

 

I hope this can imagine you the problem.

 

The part is for an end user application, the user should not care about how many profiles he creates.

 

 

Thanks 

 

Simon

0 Likes
Message 5 of 7

Anonymous
Not applicable

And If I edit the exrusion with the dialog box, its geting healthy and find all profiles.

May I can write a code that opens the dialog box, for the extrusion feature, and closes it again.

 

This would fix the problem too.

 

But i cant find a comand to do this. In the Eventwatcher SDK it shows only "edit extusion" not wich extrusion.

 

THX

 

Simon

0 Likes
Message 6 of 7

wayne.brill
Collaborator
Collaborator
Accepted solution

Hi Simon,

 

I am now able to recreate the errors. (I am not seeing a crash however - Inventor hanging or a quick exit)

 

I delete a circle from the sketch for CUT2_SW1 extrusion and that extrusion needs to be repaired.

 

When I run the rule I see the error is occurring on this line.

oExtrudeWC1.Profile = oProfileWC1

I am not sure why a problem with the sketch for CUT2_SW1 is effecting this code that is setting the profile for CUT_SW1. 

 

If I comment out the code in the rule that is setting the profile for CUT_SW1 the extrusion CUT2_SW1 is healed and no error occurs. I also find that if I move the code that is setting the profile for CUT2_SW1 before  the code setting the profile for CUT_SW1 the problems goes away.  This is true even if both CUT_SW1 and CUT2_SW1 need to be healed.

 

Please try this and let me know if your results are the same.

 

When this extrusions were created was the CUT_SW1_S sketch used in some way for the other sketches?

 

Here is the change to the code. (just moved one section above the other)

''------------------------SW1---CUT2-------------------------

Dim oSketchWC2 As PlanarSketch
oSketchWC2 = oSketches.Item("CUT2_SW1_S")

Dim oProfileWC2 As Profile
oProfileWC2 =oSketchWC2.Profiles.AddForSolid(True)

Dim oExtrudeWC2 As ExtrudeFeature = Feature.InventorFeature("CUT2_SW1")
oExtrudeWC2.Profile = oProfileWC2

'-------------------------------SW1---CUT1---------------------------------

Dim oSketchWC1 As PlanarSketch
oSketchWC1 = oSketches.Item("CUT_SW1_S")

Dim oProfileWC1 As Profile
oProfileWC1 =oSketchWC1.Profiles.AddForSolid

Dim oExtrudeWC1 As ExtrudeFeature = Feature.InventorFeature("CUT_SW1")
oExtrudeWC1.Profile = oProfileWC1




RuleParametersOutput()
InventorVb.DocumentUpdate()


''------------------------SW1---ADD-------------------------

 

 

Thanks,

Wayne

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Message 7 of 7

Anonymous
Not applicable

Hy Wayne,

 

 

Thanks for your helpful and valuable support!

 

I tryed this and my results are the same.

 

I changed the direction of the rule (move Set2 before Set1) everything went fine. There is still an warning, but I can manage it by running the rule.

The Modell performs a correct update like need it!

I proceed for the other Bodies and there is also no malfunction-fine! 

 

I think, i made a mistake by the initial building of the modell.

 

I created the first extrusion, and wrote the rule only for this element, to check if everything works.

Then i copied the element, made it independent and renamed it! May there is, deep in the dark, a dependancy back to the Original?

 

Whatever, it works now for my application.

 

Thanks for Support! KUDO+Solution!

 

 

Simon

 

 

0 Likes