Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Function can only be used in assembly error

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
ndillner343SKL
266 Views, 6 Replies

Function can only be used in assembly error

I'm running an external rule within both parts and assemblies. It's been working just fine for days now. But all of a sudden today it will no longer run within parts and it gives me an error saying it can only be run within assemblies. I've put a message box as the very first line of code and it wont even open the message. So I believe the issues not with the code itself. Please see image below.

 

ndillner343SKL_0-1671036883809.png

 

6 REPLIES 6
Message 2 of 7
WCrihfield
in reply to: ndillner343SKL

Hi @ndillner343SKL.  Can you post the code, so we can review it, if it does not contain any proprietary data?  The error makes it sound like you are using the iLogic shortcut snippet that starts with the keyword "Component", but that really is just for working with an assembly, not a part, so that may be where the problem lies.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 7
ndillner343SKL
in reply to: WCrihfield

Hi @WCrihfield,

 

I can't share the code entirely. But here is the first chunk. The External rules its calling are simply "Select Case" that are using the parameter value to determine the returned variable.

 

 
Message 4 of 7
ndillner343SKL
in reply to: WCrihfield

@WCrihfield, I found the issue. You were right it was because of a "Component." callout. But the code was only suppose to run if it was an assembly. Which is why I didn't think it would be an issue. Thanks for the response!

 

	If oDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then

 

			If oComName = oComponentName Then
				Try 
					If GoExcel.CellValue(param.Name) = "NA" Then 
						Component.IsActive(oComponentName) = False
					End If
				Catch 
					Component.IsActive(oComponentName) = True
				End Try
			End If

 

Message 5 of 7
WCrihfield
in reply to: ndillner343SKL

I don't really see anything that I suspect might cause an error like that in what you posted.  I see that you are using 'ActiveDocument' to access parameters, but are then using 'ActiveEditDocument' for defining your 'oDef' variable.  You are likely aware of this, but those could be pointing to completely different documents in some situations.  If an assembly was 'active' when you started the code, but you were also currently in 'edit mode' of a component within that assembly, the 'ActiveDocument' would remain the main assembly, but the 'ActiveEditDocument' would be the document the component you were editing represents.  But if you already had that in mind, or planned it that way, there is probably no problem there.

Another tip is that you can check if a SharedVariable exists, before trying to access its value, which can help avoid some potential errors.

I am now curious about the other two rules, and how they are identifying the document that they are to work on.  But, if there was a problem with one of them, I would assume that it would have the name of one of them in the error message, instead of this rule's name.  At this point, I'm still not sure what might be causing an odd sounding error like that.

 

Oops... OK, I just read your later posts after posting this one. 😂

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 7
WCrihfield
in reply to: ndillner343SKL

If you need to replace that little bit of code, there are API ways of doing the same thing too, but it would obviously take more code to do the API way.  IsActive = Not Suppressed, and the ComponentOccurrence object has a ReadOnly property called Suppressed, for checking its current status, and two methods (Suppress & Unsuppress) for handling changes to that status.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 7
ndillner343SKL
in reply to: WCrihfield

I will give these a try. Thank you!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report