ilogic Why can this code fail

ilogic Why can this code fail

Darkforce_the_ilogic_guy
Advisor Advisor
670 Views
6 Replies
Message 1 of 7

ilogic Why can this code fail

Darkforce_the_ilogic_guy
Advisor
Advisor

I have a very complex code... and I have a problem the code fail .

 

 

so I want to know why can this code fail

 

Dim oAsmCompDef As AssemblyComponentDefinition
	
'this one under is the one that cause the error.
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
	

what can cause it to fail  ?

 

0 Likes
671 Views
6 Replies
Replies (6)
Message 2 of 7

Darkforce_the_ilogic_guy
Advisor
Advisor
Dim doc = ThisDoc.Document
	Dim sDocumentSubType As String = doc.SubType
	If sDocumentSubType <> "{4D29B490-49B2-11D0-93C3-7E0706000000}"  And  sDocumentSubType <>"{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then '  = "Part"
	'------------------
	debug("Colour Assambly")
	Dim oAsmCompDef As AssemblyComponentDefinition
	debug("Loading Variable Finish 0,5")
	
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition 


debug("Loading Variable Finish 1")
'define view rep collection
Dim oViewReps As DesignViewRepresentations
oViewReps = oAsmCompDef.RepresentationsManager.DesignViewRepresentations
debug("Loading Variable Finish 2")
'define view rep 
Dim oViewRep As DesignViewRepresentation
debug("Loading Variable Finish 3")

Dim NumberOfView = oViewReps.Count
' get Manager of Representations
debug("Loading Variable Finish 4")
 Dim dViewRepMgr As RepresentationsManager
 dViewRepMgr = oAsmCompDef.RepresentationsManager
 debug("Loading Variable Finish 5")
 'Get active Representation View
 Dim dViewRep As DesignViewRepresentation
 dViewRep = dViewRepMgr.ActiveDesignViewRepresentation
 debug("Loading Variable Finish 6")
 debug("Loading Variable Finish")
 Try
For i=1 To NumberOfView 
oViewReps.Item(i).Activate
iLogicVb.RunExternalRule("SurfaceColour")
iLogicVb.UpdateWhenDone = True
Next
Catch
	dViewRepMgr.DesignViewRepresentations.Item(1).Activate
	End Try
	Try
dViewRep.Activate
Catch
	
End Try
	

	'---------------
	'iLogicVb.RunExternalRule("SurfaceColour") 
	
	
	End If 
0 Likes
Message 3 of 7

chandra.shekar.g
Autodesk Support
Autodesk Support

@Darkforce_the_ilogic_guy,

 

After looking into posted iLogic code, guessing that error might be occurred in running external rule. Please provide non confidential external iLogic code to investigate.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 4 of 7

I found out it was not so most the code. but there seens to be somthing Special about the iam file It still work on other Iam files, and I not sure what so special about it ... I did found a workaround for now … then sind I still do Not fullly understand why .. I do not know it is will give problem later.  The code that fail , was the last line of code I send out in the first post with code. 

 

I use  an Try and Catch to jumb over a large piece of the code that was not needed anyway on the fil that fail. When sind 100´s of files work with this code and just one did not … I do not know if this is fix or it will come up again a new fil 

0 Likes
Message 5 of 7

chandra.shekar.g
Autodesk Support
Autodesk Support

@Darkforce_the_ilogic_guy,

 

Can you please provide non confidential assembly file to reproduce the behavior?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 6 of 7

JaneFan
Autodesk
Autodesk

Hey @Darkforce_the_ilogic_guy , 

 

Is it possible some document of different document type being opened as ActiveDocument during the run time? Please try to get ThisApplication.ActiveDocument.DocumentType to see whether it is caused by the document type not being correct:

If ThisApplication.ActiveDocument.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then 
	oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Else 
	MsgBox("Active document isn't Assembly: " + ThisApplication.ActiveDocument.FullFileName)
End If 

 




Jane Fan
Inventor/Fusion QA Engineer
0 Likes
Message 7 of 7

Skadborg.NTI
Advocate
Advocate

You try to get AssemblyComponentDefinition from ActiveDocument. Eventhough you have checked that you have an assembly as active doc, then this sometimes fails.

Seems as if you only can access properties and methods on Document and not on AssemblyDocument. So make sure you have an object of the type AssemblyDocument:

Dim doc = ThisDoc.Document
If doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
	Dim asmDoc As AssemblyDocument = ThisDoc.Document
	Dim oAsmCompDef As AssemblyComponentDefinition
	oAsmCompDef = asmDoc.ComponentDefinition 
	...
0 Likes