Place the model in a text list to current drawing by iLogic or VB.NET

Place the model in a text list to current drawing by iLogic or VB.NET

ngdnam88
Advocate Advocate
504 Views
5 Replies
Message 1 of 6

Place the model in a text list to current drawing by iLogic or VB.NET

ngdnam88
Advocate
Advocate

Dears All,

I often works with iPart/iAssembly drawings. I wanna place all member to working drawing. Please help me an iLogic/VB.NET code to place a drawing view automatic each member has got one view. At the moment I have got an idea that put all member's filename to text list file then place them to working drawing.

Thank you very much!

0 Likes
505 Views
5 Replies
Replies (5)
Message 2 of 6

A.Acheson
Mentor
Mentor

This post here should help. It places a member to the drawing, changes the partslist to the active member, saves,closes and repeats. 

Code below:

'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
0 Likes
Message 3 of 6

ngdnam88
Advocate
Advocate

Thanks @A.Acheson 
I tried your code but it return each member to new one drawing. I just wanna place all member to one drawing (each member has got one view). Could you please help me? Thanks,

0 Likes
Message 4 of 6

A.Acheson
Mentor
Mentor

Hi @ngdnam88  there will be many ways to achieve this but it is heavily depended on what outcome your wanting. Here is the API sample to place a file to a sheet set.

 

Another method is to place the view manually and set the position on the sheet. See help file in VBA

And here is code written for the ilogic editor. 


If your testing the code you can remove  the for each member loop and just supply a single member file path. This will avoid lengthy wait time when testing. Or alternatively set up a new rule and just test getting a view added to the sheet then bring in a for loop for next sheet etc.

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

ngdnam88
Advocate
Advocate
Finally, I got solution after tried your guide. Thanks for your help.
0 Likes
Message 6 of 6

A.Acheson
Mentor
Mentor

Hi @ngdnam88 

Glad to hear you got a solution. Would it be possible to press the accept as solution on the post that helped? If it is the code you worked on could you post it here for others to benefit from. Thanks. 

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