Visual studio : I cannot get the feature suppress

Visual studio : I cannot get the feature suppress

bhavik4244
Collaborator Collaborator
694 Views
6 Replies
Message 1 of 7

Visual studio : I cannot get the feature suppress

bhavik4244
Collaborator
Collaborator

Hello,

I am trying to make add in with a code below, I bit of have idea where I got the isuue but don't have solution for that.

 

Please help if someone can.

 

The iLogic code working fine but it dosen't catch the feature through vb.net.

 

 

Private Sub m_sampleButton_OnExecute(Context As NameValueMap) Handles m_sampleButton.OnExecute
'MsgBox("Button was clicked.")

Dim asmDoc = g_inventorApplication.ActiveDocument
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = g_inventorApplication.ActiveDocument.ComponentDefinition
Dim oOccurrence As ComponentOccurrence

'Dim Part As PartDocument = g_inventorApplication.PartDocument
Dim oPdef As PartComponentDefinition = g_inventorApplication.ActiveDocument.ComponentDefinition
Dim Feature As PartFeature = oPdef.Features


For Each oOccurrence In oAsmCompDef.Occurrences
'MsgBox(oOccurrence.Name)
If oOccurrence.Name.Contains("Improved 80mm") Then
'oOccurrence.count
MsgBox(oOccurrence.Name)

Feature.IsActive(oOccurrence.Name, "Revolution1") = False
Feature.IsActive(oOccurrence.Name, "Rectangular Pattern1") = False
End If

If oOccurrence.Name.Contains("Improved Guide Corner") Then
MsgBox(oOccurrence.Name)
Feature.IsActive(oOccurrence.Name, "Revolution1") = False
Feature.IsActive(oOccurrence.Name, "Circular Pattern1") = False
End If
Next


End Sub


Bhavik Suthar
0 Likes
Accepted solutions (1)
695 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor

Hi @bhavik4244.  I admittedly don't use Visual Studio much or create add-ins (due to corporate restrictions), but I'm pretty sure I know why it is not working for you.  That Feature.IsActive() method is an iLogic only snippet (defined within the iLogic add-in), so you will need to do that process through the normal API route.  All that snippet does is change the 'Suppressed' state of the feature.  It will surely be more of a pain in the butt doing it the API way, but that's part of the trade-off.  Basically get the document being represented by the component, then get its component definition, then its features, then get that feature by name using PartFeatures.Item("featureName").  If you need help coding that, just let us know.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 7

WCrihfield
Mentor
Mentor
Accepted solution

Here is just an idea I threw together, that may or may not work for you, just as a starter.  I created a Function go get a named feature from within a supplied component and return that feature.  I suppose that Function could just as easily be renamed OccurrenceFeatureIsActive, and turned into a Sub that simply sets the feature's suppression to a supplied Boolean value, but you get the point.  Just a quickie attempt to make a 'side routine' for use in vb.net that could be used as somewhat of a replacement for the Feature.IsActive() iLogic method.

Private Sub m_sampleButton_OnExecute(Context As NameValueMap) Handles m_sampleButton.OnExecute
	'MsgBox("Button was clicked.")
	Dim asmDoc = g_inventorApplication.ActiveDocument
	Dim oAsmCompDef As AssemblyComponentDefinition
	oAsmCompDef = g_inventorApplication.ActiveDocument.ComponentDefinition
	Dim oOccurrence As ComponentOccurrence
	
	For Each oOccurrence In oAsmCompDef.Occurrences
		Dim oOccName As String = oOccurrence.Name
		'MsgBox(oOccurrence.Name)
		If oOccName.Contains("Improved 80mm") Then
			'oOccurrence.count
			MsgBox(oOccName)
			Dim oRev1 As PartFeature = GetOccurrenceFeature(oOccurrence, "Revolution1")
			Dim oRecPtrn1 As PartFeature = GetOccurrenceFeature(oOccurrence, "Rectangular Pattern1")
			oRev1.Suppressed = True
			oRecPtrn1.Suppressed = True
		End If

		If oOccName.Contains("Improved Guide Corner") Then
			MsgBox(oOccName)
			Dim oRev1 As PartFeature = GetOccurrenceFeature(oOccurrence, "Revolution1")
			Dim oCircPtrn1 As PartFeature = GetOccurrenceFeature(oOccurrence, "Circular Pattern1")
			oRev1.Suppressed = True
			oCircPtrn1.Suppressed = True
		End If
	Next
End Sub

Private Function GetOccurrenceFeature(oOcc As ComponentOccurrence, oFeatureName As String) As PartFeature
	Dim oOccDoc As Document = oOcc.ReferencedDocumentDescriptor.ReferencedDocument
	Dim oFeatures As Object 'PartFeatures from Part ; Features from Assembly
	If TypeOf oOccDoc Is PartDocument Then
		Dim oPDoc As PartDocument = oOccDoc
		oFeatures = oPDoc.ComponentDefinition.Features
		'SheetMetalFeatures would be under a SheetMetalComponentDefinition
	ElseIf TypeOf oOccDoc Is AssemblyDocument Then
		Dim oADoc As AssemblyDocument = oOccDoc
		oFeatures = oADoc.ComponentDefinition.Features
	End If
	Dim oFeature As PartFeature 'both Item() returns PartFeature
	Try
		oFeature = oFeatures.Item(oFeatureName)
	Catch
	End Try
	Return oFeature 'may be Nothing if not found
End Function

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 7

bhavik4244
Collaborator
Collaborator

@WCrihfield 

 

Thanks but it doen't work.

 

Is there any source/material where I can see some insight of Visual studio and Inventor?

 

I have seen the Inventor API help but it seems bit difficult to understand.


Bhavik Suthar
0 Likes
Message 5 of 7

WCrihfield
Mentor
Mentor

I probably wouldn't be much help there.  Although I have Visual Studio 2019 (free version) installed, I haven't used it much, because I don't think I have everything set-up correctly for my very narrow needs.  Since I am not a software developer and don't have a degree in computer programming (other than CNC), I was not sure how to set everything up.  And since I don't even have administrator's rights on my work PC (again, due to corporate nonsense), I can not 'register' dll's, and I have not been able to fully explore the possibilities.

Learning vb.net, VBA, & iLogic for me has been fully by exploration, reading, trial & error experience, etc.

 

If you do find an easy to follow guide for properly installing Visual Studio, setting it all up property for use with (all things Inventor related), and maybe how to be able to make use of it without administrator's rights, please let me know, because I would be very interested in further pursuing that.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 7

Michael.Navara
Advisor
Advisor

"It doesn't work" is not good response. Why it doesn't work? Do you get some error message? Do you get some compile error?

I test this function "GetOccurrenceFeature" and it works as expected.

 

 

 

 

0 Likes
Message 7 of 7

bhavik4244
Collaborator
Collaborator

@Michael.Navara  thanks for pointing the mistake I did in hurry,I didn't check whole code other then Function for GetOccuranceFeature. With fresh mind in morning I started from scratch and I got the code running as expected.

 

@WCrihfield Thanks a lot, code worked for me. I am bit sure that without admin rights it's not possible to deal with installation/dll add-in for visual studio. I am also not a software developer but learn on the Job and make trails and any question arise then ask to the experts like you on forum 🙂 again thanks!


Bhavik Suthar
0 Likes