Use Ilogic to select iassembly member for the parts list in a drawing

Use Ilogic to select iassembly member for the parts list in a drawing

briant.markham
Enthusiast Enthusiast
1,346 Views
11 Replies
Message 1 of 12

Use Ilogic to select iassembly member for the parts list in a drawing

briant.markham
Enthusiast
Enthusiast

I have an Ilogic rule that selects the right drawing view based on the drawing file name which is also the iassembly member name, and it works for iparts and iassemblies but for iassemblies I also need to select the right member for the "parts list" too. I am have some difficulty doing this, here is the rule that selects the drawing view.

 

Dim oView As DrawingView
oView = ActiveSheet.View("VIEW1").View
docname=ThisDoc.FileName(False) 'without extension
oView.ActiveMemberName = docname 
'MessageBox.Show(docname, "Title")

 

0 Likes
Accepted solutions (1)
1,347 Views
11 Replies
Replies (11)
Message 2 of 12

clutsa
Collaborator
Collaborator
0 Likes
Message 3 of 12

briant.markham
Enthusiast
Enthusiast

The code I posted does that for the drawing views, I would like to add the same functionality for the parts list.

0 Likes
Message 4 of 12

clutsa
Collaborator
Collaborator

Try this...

Dim oView As DrawingView
oView = ActiveSheet.View("VIEW1").View
docname=ThisDoc.FileName(False) 'without extension
docnamearr = New String() {docname} oView.ActiveMemberName = docname
ActiveSheet.PartsList.Item(1).MembersToInclude() = docnamearr 'MessageBox.Show(docname, "Title")

(Assumes you only have one parts list) 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 5 of 12

briant.markham
Enthusiast
Enthusiast

I get this error "Error on Line 6 : 'PartsList' is not a member of 'Autodesk.iLogic.Interfaces.ICadDrawingSheet'."

0 Likes
Message 6 of 12

clutsa
Collaborator
Collaborator

Sorry it's plural "PartsLists"

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 7 of 12

briant.markham
Enthusiast
Enthusiast

Still getting the same error. 

0 Likes
Message 8 of 12

clutsa
Collaborator
Collaborator
Accepted solution

Here is the code I'm using ( it was meant for something else and I just modified it)

Dim drawingDoc As DrawingDocument
drawingDoc = ThisDrawing.Document

For v = 1 To drawingDoc.ActiveSheet.DrawingViews.Count
    oView = ActiveSheet.View("VIEW" & v)
    doc = oView.ModelDocument

	If doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
	  	member = doc.ComponentDefinition.iAssemblyMember.ParentFactory.DefaultRow.MemberName
		member2 = New String() {member}
	Else If doc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		member = doc.ComponentDefinition.iPartMember.ParentFactory.DefaultRow.MemberName
		oView.View.ActiveMemberName = member
	End If
		oView.View.ActiveMemberName = member
Next

If drawingDoc.ActiveSheet.PartsLists.Count > 0 Then drawingDoc.ActiveSheet.PartsLists.Item(1).MembersToInclude() = member2

I think you just need to declare your doc type but my test file doesn't follow your naming structure so I can't verify this. 

Dim oView As DrawingView
Dim doc As DrawingDocument = ThisApplication.ActiveDocument
oView = ActiveSheet.View("VIEW1").View
docname=ThisDoc.FileName(False) 'without extension
docnamearr = New String() {docname}
oView.ActiveMemberName = docname 
doc.ActiveSheet.PartsLists.Item(1).MembersToInclude() = docnamearr
'MessageBox.Show(docname, "Title")

 

 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 9 of 12

briant.markham
Enthusiast
Enthusiast

@clutsa wrote:

I think you just need to declare your doc type but my test file doesn't follow your naming structure so I can't verify this. 

Dim oView As DrawingView
Dim doc As DrawingDocument = ThisApplication.ActiveDocument
oView = ActiveSheet.View("VIEW1").View
docname=ThisDoc.FileName(False) 'without extension
docnamearr = New String() {docname}
oView.ActiveMemberName = docname 
doc.ActiveSheet.PartsLists.Item(1).MembersToInclude() = docnamearr
'MessageBox.Show(docname, "Title")

 

 


That worked great, I don't suppose you could explain it? Is there a reference for what does what?

0 Likes
Message 10 of 12

clutsa
Collaborator
Collaborator

@briant.markham wrote:

 

That worked great, I don't suppose you could explain it? Is there a reference for what does what? 

I can explain but not well...

Dim doc As DrawingDocument = ThisApplication.ActiveDocument
MessageBox.Show(doc.ActiveSheet.ToString, "Title") 'returns "System._ComObject"
MessageBox.Show(ActiveSheet.ToString, "Title") 'returns "Autodesk.iLogic.Runtime.CadDrawingSheet"

If you don't specifically declare your object Inventor is forced to guess. iLogic generally does a good job at guessing but in this case CadDrawingSheet doesn't have all the same methods and properties that you get from the Com Object. It's best practice to declare the objects that you can so you don't end up making calls against objects thinking they are one type but the computer picked something different. 

I remember some code I had once that I couldn't get to work and was ready to give up when I finally added a debug.Print () statement and found out it wouldn't work because I hadn't declared a couple of variables. Turns out the compiler had guessed that myVar = 3 was a string not an integer and  myVar + myVar = 33. 

I use the VBA "object browser" and "locals" window to poke around and find what I want and then write it to iLogic.

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 11 of 12

briant.markham
Enthusiast
Enthusiast

Now I am getting this error

 

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Inventor.PartsList.set_MembersToInclude(Object )
   at ThisRule.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 Likes
Message 12 of 12

clutsa
Collaborator
Collaborator

1. Same code as above?

2. Is your drawing document the active document?

3. Are you doing VBA or iLogic (I assume iLogic)?

4. What have you changed sense it stopped working?

 

Try adding message boxes to verify what your variables are set to. This will also give you an idea of what line is throwing the error.

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes