Auto updation of drawing views of iparts to Active factory member with ilogic programme

Auto updation of drawing views of iparts to Active factory member with ilogic programme

Anonymous
Not applicable
1,206 Views
7 Replies
Message 1 of 8

Auto updation of drawing views of iparts to Active factory member with ilogic programme

Anonymous
Not applicable

@clutsa@A.Acheson
Respected members,
awaiting for your reply

https://forums.autodesk.com/t5/inventor-customization/change-ipart-member-on-a-drawing-possible/td-p...

Dim oView As DrawingView
oView = ActiveSheet.View("VIEW1").View
Dim doc as AssemblyDocument
doc = ThisDrawing.ModelDocument
member = doc.ComponentDefinition.iAssemblyMember.ParentFactory.DefaultRow.MemberName
'MessageBox.Show(member, "Title")
oView.ActiveMemberName = member

Thank you for the above forum topic, this ilogic has worked for me when I change the reference assembly model by "replace model option" in the inventor draft,

 

will u plz, help me for a code in a similar way for iparts updation in drawing view of inventor draft,

where ilogic will catch the ipart member name from the assembly table & will update the exact active factory member automatically

Capture.PNG




0 Likes
1,207 Views
7 Replies
Replies (7)
Message 2 of 8

clutsa
Collaborator
Collaborator
Dim oView As DrawingView
oView = ActiveSheet.View("VIEW1").View
Dim doc As PartDocument
doc = ThisDrawing.ModelDocument
member = doc.ComponentDefinition.iPartMember.ParentFactory.DefaultRow.MemberName
'Logger.Debug(member)
oView.ActiveMemberName = member

The above code should work. I was getting an error because the factory I was using was outdated and complained that the members hadn't been generated so make sure you have members generated. I also had an error when switching from "Active Factory Member" so make sure your drawing view is selected to an actual member.

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 3 of 8

WCrihfield
Mentor
Mentor

Here is a more in-depth code that checks which DocumentType and which iObject type the view is representing first, then follows through to get the 'default' member name to use for setting the view's 'ActiveMemberName'.

Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oDefaultMember As String
If ThisDrawing.ModelDocument.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
	Dim oADoc As AssemblyDocument = ThisDrawing.ModelDocument
	Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
	If oADef.IsiAssemblyFactory Then
		oDefaultMember = oADef.iAssemblyFactory.DefaultRow.MemberName
	ElseIf oADef.IsiAssemblyMember Then
		oDefaultMember = oADef.iAssemblyMember.ParentFactory.DefaultRow.MemberName
	End If
	'MsgBox("Default iAssembly member name is:  " & oDefaultMember,,"")
ElseIf ThisDrawing.ModelDocument.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
	Dim oPDoc As PartDocument = ThisDrawing.ModelDocument
	Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
	If oPDef.IsiPartFactory Then
		oDefaultMember = oPDef.iPartFactory.DefaultRow.MemberName
	ElseIf oPDef.IsiPartMember Then
		oDefaultMember = oPDef.iPartMember.ParentFactory.DefaultRow.MemberName
	End If
	'MsgBox("Default iPart member name is:  " & oDefaultMember,,"")
End If
If String.IsNullOrEmpty(oDefaultMember) Then
	MsgBox("No member name was retrieved. Exiting.", , "")
	Exit Sub
End If
Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
Dim oView As DrawingView = oSheet.DrawingViews.Item(1)
oView.ActiveMemberName = oDefaultMember

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 8

Anonymous
Not applicable
Sir,
thanking you for your quick reply and kind attention, with this communication I would like to add that
I have prepared idw for “iassly”, (placed FV, SV, PLAN of asly, and placed detailed views of iparts with base view option of each ipart model individually with the “Active factory member” option activated)
for different combination once made in assly I copy that model & idw dwg as well in a different location and use “replace the model command” from idw & run above rule, assly gets updated but iparts which are at combinations used as per that iassly table don’t get updated in drawing views, I want illogic rule for those iparts views updating as well (as per that ipart combination mentioned in iasly’s row).
I am not a programmer, kindly give me ready illogic with notations what I need to edit in the programme to my end as well.
0 Likes
Message 5 of 8

A.Acheson
Mentor
Mentor

@Anonymous 

 

If I read your post correctly this rule might be what you are looking for. It might be more for documenting iAssemblies  but you can adapt it to your case once you see it's functionality.  Reference post I have used are here Save As, iPart Replace, iAssemblyPartslist

 

'Step1: Place the iAssembly on a drawing
'Step2: Select member#1 to be the active member for the View 
'Step3: Place partslist on sheet(Optional)
'Step4: Save the drawing using the first factory member as the filename.
'Step5: Run this rule
Sub Main
Check = MessageBox.Show("Loop through factory members, This will take a while. Are you sure?" _
, "Ilogic Instructions", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
If  Check = vbYes Then 
 	
	Dim oDrawingDoc As DrawingDocument
	oDrawingDoc = ThisApplication.ActiveDocument

	Dim oView As DrawingView
	oView = oDrawingDoc.ActiveSheet.DrawingViews(1)
	 
	Dim oAssyDoc As AssemblyDocument
	oAssyDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument

	Dim oDef As AssemblyComponentDefinition
	oDef = oAssyDoc.ComponentDefinition


	'Make sure we have an iAssemblyMember.
	If Not oDef.IsiAssemblyMember = True Then
	    MsgBox ("Chosen document is not a iAssemblyMember.", vbExclamation)
	    Exit Sub
	End If
		Dim oFactory As iAssemblyFactory 
		oFactory = oDef.iAssemblyMember.ParentFactory
		
		Dim FirstMemberName As String
		FirstMemberName = oFactory.FileNameColumn(1).Value

		'Create ArrayList Of Members to Include in Partslist
		FirstMemberArray = New String() {FirstMemberName}

		Dim FirstPath As String
		FirstPath = oAssyDoc.FullFileName
		
		Dim NewPath As String
		For i =1 To oFactory.TableRows.Count - 1
			 
			 oAssyDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument

			NewPath = Replace(oAssyDoc.FullFileName, oFactory.FileNameColumn(i).Value, oFactory.FileNameColumn(i + 1).Value)
		
			 ThisApplication.UserInterfaceManager.DoEvents
		     ThisApplication.StatusBarText = "Changing Member referencing......"
			
			' Generate the member and file, (overwrites member file or creates new file)
			Call oFactory.CreateMember(i + 1)
			Call oDrawingDoc.Update2(True)
			
			'Get MemberName 
			Dim NewMemberName As String
		  	NewMemberName = oFactory.FileNameColumn(i + 1).Value
			
			'Create ArrayList Of Members to Include in Partslist
			NewMemberArray = New String() {NewMemberName}
			
			'Change partslist to match member in the view
			If oDrawingDoc.ActiveSheet.PartsLists.Count > 0 Then oDrawingDoc.ActiveSheet.PartsLists.Item(1).MembersToInclude() = NewMemberArray
			
			'Change the view to new member
			Call oView.ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(NewPath)
			
			'Perform a Saveas Drawing
			Try
				Call oDrawingDoc.SaveAsInventorDWG(Replace(oDrawingDoc.FullFileName, oFactory.FileNameColumn(1).Value, oFactory.FileNameColumn(i+1).Value), True)

				'Do Something else like update iproperties

			Catch
				MessageBox.Show("Error", "Title")
				End Try
		
		Next
			' On loop finish, change model reference and partlsist back to member 1( to avoid saving the wrong member to filename)
			Try
				Call oView.ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(FirstPath)

				 If oDrawingDoc.ActiveSheet.PartsLists.Count > 0 Then oDrawingDoc.ActiveSheet.PartsLists.Item(1).MembersToInclude()= FirstMemberArray

			Catch
				MessageBox.Show("Error", "Title")
			End Try	
		
	Else
	End If
End Sub

 

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 6 of 8

gradecki
Observer
Observer

Hello,

 

first of all I want to thank you for the great rule, it works very well for me and it saves me a lot of time.

The rule works great when the file name and the member name are the same.

But when the member name is different from file name it doesn't work any more.

 

For example: my file/part name is 8-2-320000-01, -02, -03 but member name must have a real, given name, for example Roller L=50 mm, Roller L=100 mm, Roller L=300 mm and I can't change it because we use this member names in many projects for a very long time.

I know which part of code makes problem but I can’t figure out how to change it.

It’s about this part of the code:

 

'Change partslist to match member in the view
If oDrawingDoc.ActiveSheet.PartsLists.Count > 0 Then oDrawingDoc.ActiveSheet.PartsLists.Item(1).MembersToInclude() = NewMemberArray

 I’m getting an error message, when when file and member name are different.

I would be very grateful for your help in solving this problem

0 Likes
Message 7 of 8

A.Acheson
Mentor
Mentor

@gradecki  You just need to change which column in the factory table the member name is being referenced from. 

Change "oFactory.FileNameColumn(1)" to "oFactory.TableColumns("Member")"

 

The two snippets to change are the first member

	Dim FirstMemberName As String
		FirstMemberName = oFactory.TableColumns("Member").Item(1).Value

and the indexed member

'Get NewMemberName 
			Dim NewMemberName As String
		  	NewMemberName = oFactory.TableColumns("Member").Item(i + 1).Value

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 8 of 8

gradecki
Observer
Observer
136 / 5 000
Wyniki tłumaczenia
Now it works perfectly for me.
Thanks again for your help and save time making 500 drawings!
Regards
Wojtek
0 Likes