Ipart factory members changing and dxf export

Ipart factory members changing and dxf export

darshitparmar8268
Participant Participant
2,838 Views
26 Replies
Message 1 of 27

Ipart factory members changing and dxf export

darshitparmar8268
Participant
Participant

Hello all,

hope you are doing great! I have a project which i am working on. I have an ipart factory document in which i have a part with 200 model state or instances . I made a drawing for one part and now i want to export that drawing as a dxf. This is easy for one or two part but i have more than 200 so i want to automate the process in a way that it loops through all the ipart instances and save dxf for each of them! I am struggling to find the write script so if anyone can help me here ! Would appreciate your guidance guys 

 

thank you

0 Likes
Accepted solutions (2)
2,839 Views
26 Replies
Replies (26)
Message 2 of 27

A.Acheson
Mentor
Mentor

Hi @darshitparmar8268 

Are you using a part with model states or an ipart? The two are different so you will need to be specific about which document object your using. If your going the drawing and dxf route you will need to produce a drawing for each variation then export to dxf so two completly different operations. Can you attach your code attempt here? 

Here is the API sample for exporting a dxf from a drawing written in vba. It will only require a few tweaks to change to VB.NET. 

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

darshitparmar8268
Participant
Participant

Hello @A.Acheson, thank you for your feedback!

 

I am working with an Ipart yes!

 

darshitparmar8268_0-1687691948039.png

My ipart does look something like this. Under the “table” category i have more than hundred of configurations! 

Secondly, going back to script, I dont have any sample with me yet because I am still under the cloud of how to start something like this. But i have a flow chart if thats what can help us getting solution for this.

 

1st step : I have created a template drawing with one of the ipart configuration. 

2nd step: I want to save this drawing then export as a dxf with the name of the configuration so i can identity them later. For the dxf export, inventor has a snippet ready to use so i guess it would require some tweaks to save  the file it with the same file-name as configuration.

 

3rd step: i want to change configuration one by onein the drawing till the end, and for each change, i want to save the drawing with updates and save dxf for the same!

 

this is what my path looks like! Please let me know if you still have any doubts or if I can make myself more clear on the topic.

 

thank you for your time and efforts 

0 Likes
Message 4 of 27

A.Acheson
Mentor
Mentor
Accepted solution

Hi @darshitparmar8268 

So what you are showing there is the iPart factory file. Here is the link to that iPartFactory object in the API Help. Luckily there is a few samples on this forum going back a few years. Here is one adapted for the ilogic environment from this source here.

 

Requirements create a drawing of the first member and save it. The code will change the member and save as a new drawing. You can drop in the sub routine for dxf creation after each save. 

Sub Main

	Dim oDrawing As DrawingDocument = ThisApplication.ActiveDocument
	Dim oPath As String = "C:\Users\hfljf\Desktop\TestFolder" 'Folder to save the drawings
	Dim oFactory As iPartFactory
	
	For Each oView As DrawingView In oDrawing.ActiveSheet.DrawingViews
		Dim oDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
		oFactory = oDoc.ComponentDefinition.iPartMember.ParentFactory
		Exit For
	Next
	
	If oFactory Is Nothing = False Then
		For Each oRow As iPartTableRow In oFactory.TableRows
			For Each oView In oDrawing.ActiveSheet.DrawingViews
				If oView.ActiveMemberName <> oRow.MemberName Then oView.ActiveMemberName = oRow.MemberName
				oDrawing.Update
				Do While oView.IsUpdateComplete = False
					Call ThisApplication.UserInterfaceManager.DoEvents
				Loop
			Next
			oDrawing.SaveAs(oPath & "\" & oRow.MemberName & ".dwg", True)
		Next
	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 5 of 27

darshitparmar8268
Participant
Participant

thank you so much @A.Acheson ! This worked at very large extent. 
there are still few things which i wish you could help me with.

 

1). All the drawing file which have been saved were . DWG format. I want to save them as . IDW as in inventor drawing file. 

2). the dxf export rule ! Where should insert it or i can send it here and maybe you can help me by tweaking it.

 

3). I have couple of other ilogic rules in my document which i want to run before it save the document so where would be the place place to insert update rule for those  rules in your given script! The rules name are “scale update” and “dxf export” 

 

i am also attaching a snippet which export the dxf but it requires the file name tweak and i wish you could help me with that!

 

Thank you so much for your time Alan! 

 



 

0 Likes
Message 6 of 27

A.Acheson
Mentor
Mentor

Hi @darshitparmar8268 

Unfortuantely I am not in front of the computer now but if you attach the  compiled sub routines and walk through the difficulties your having.

 

For changing the drawing extension ensure your starting from an idw and change the extension to .idw.

 

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

Frederick_Law
Mentor
Mentor

My iLogic to export dxf for ModelState:

 

Public Sub Main()
Dim oDoc As PartDocument
Dim oCompDef As ComponentDefinition
Dim oModelStates As ModelStates
Dim oModelState As ModelState
Dim oDataIO As DataIO
Dim sOut As String
oDoc = ThisApplication.ActiveDocument
Logger.Info("FlatOut" & oDoc.DisplayName)
oCompDef = oDoc.ComponentDefinition
' Get the DataIO object
oDataIO= oCompDef.DataIO
' Build the string that defines the format of the DXF file
sOut = "FLAT PATTERN DXF?AcadVersion=2000&InvisibleLayers=IV_TANGENT;IV_BEND;IV_BEND_DOWN;IV_ROLL;IV_ROLL_TANGENT&RebaseGeometry=True"

If oCompDef.IsModelStateFactory Then
	Logger.Info("ModelState in file")
	oModelStates = oCompDef.ModelStates
	For Each oModelState In oModelStates
		oModelState.Activate
		oCompDef.FlatPattern.Edit
		Logger.Info(oDoc.DisplayName & " " & oModelState.Name)
		Logger.Info(iProperties.Value("Project", "Part Number"))
		' Skip Primary
		If oModelState.Name <> ThisServer.LanguageTools.CurrentPrimaryModelStateString
			' Create DXF file
			oDataIO.WriteDataToFile(sOut, "\\shared\DXF Programming\" + iProperties.Value("Project", "Part Number") + ".dxf")
		End If
		oCompDef.FlatPattern.ExitEdit
	Next
    oModelStates.Item(1).Activate
Else
  Logger.Info("Normal file")
  Logger.Info(iProperties.Value("Project", "Part Number"))
  oDataIO.WriteDataToFile(sOut, "\\shared\DXF Programming\"+iProperties.Value("Project", "Part Number")+".dxf")
End If
End Sub

 

Options for DXF export:

https://help.autodesk.com/view/INVNTOR/2023/ENU/?guid=GUID-451B918E-9374-442D-B9AE-31A8C83674B7

 

Message 8 of 27

dparmarF6BDE
Enthusiast
Enthusiast
Hello @A.Acheson,
Thank you for the message. I looked at couple of threads regarding dxf exporting and name changing but all of them are about multiple iproperties putting in the file name and i got confused. here is the snippet which I want to tweak in a way that it captures the "part name" of the current ipart instance and save dxf with the file name same as the part name, also i wanna save all the dxf in a desired folder which this script is not letting me do it. Can you please help me with these changes?
thank you






' Get the DXF translator Add-In.
Dim DXFAddIn As TranslatorAddIn DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}") 'Set a reference to the active document (the document to be published). Dim oDocument As Document oDocument = ThisApplication.ActiveDocument Dim oContext As TranslationContext oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism ' Create a NameValueMap object Dim oOptions As NameValueMap oOptions = ThisApplication.TransientObjects.CreateNameValueMap ' Create a DataMedium object Dim oDataMedium As DataMedium oDataMedium = ThisApplication.TransientObjects.CreateDataMedium ' Check whether the translator has 'SaveCopyAs' options If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then Dim strIniFile As String strIniFile = "C:\temp\dxfout.ini" ' Create the name-value that specifies the ini file to use. oOptions.Value("Export_Acad_IniFile") = strIniFile End If 'Set the destination file name oDataMedium.FileName = ThisDoc.PathAndFileName(False) & ".dxf" 'Publish document. DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) 'Launch the dxf file in whatever application Windows is set to open this document type with i = MessageBox.Show("Preview the DXF file?", "Title",MessageBoxButtons.YesNo,MessageBoxIcon.Question) If i = vbYes Then ThisDoc.Launch(oDataMedium.FileName)

 

0 Likes
Message 9 of 27

A.Acheson
Mentor
Mentor

To start with you will need to put the code into a  sub routine to make it easier to structure the rule.

Then as arguments supply in the drawing document and filename you want to use. 

 You allready have the filename before you save the drawing so set that to a  String variable like

Dim dxfFileName As String = oPath & "\" & oRow.MemberName & ".dxf"

 

This is the filename line in the dxf sub routine.

 

oDataMedium.FileName = dxfFileName

 

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

dparmarF6BDE
Enthusiast
Enthusiast

Thanks for the solution @A.Acheson i will try it asap,
Meanwhile, I am getting this new error which I was not getting in my other computer. this is the snapshot of error and also I pasted the same script i used. Do you know what could be the issue  here?

Thanks again and sorry for bothering you like this 😥😣

dparmarF6BDE_0-1687815901664.png

 

Sub Main

	Dim oDrawing As DrawingDocument = ThisApplication.ActiveDocument
	Dim oPath As String = "C:\PBW Workspace\HS-RAIL-IDW" 'Folder to save the drawings
	Dim oFactory As iPartFactory
	
	For Each oView As DrawingView In oDrawing.ActiveSheet.DrawingViews
		Dim oDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
		oFactory = oDoc.ComponentDefinition.iPartMember.ParentFactory
		Exit For
	Next
	
	If oFactory Is Nothing = False Then
		For Each oRow As iPartTableRow In oFactory.TableRows
			For Each oView In oDrawing.ActiveSheet.DrawingViews
				If oView.ActiveMemberName <> oRow.MemberName Then oView.ActiveMemberName = oRow.MemberName
				oDrawing.Update
				Do While oView.IsUpdateComplete = False
					Call ThisApplication.UserInterfaceManager.DoEvents
				Loop
			Next
			oDrawing.SaveAs(oPath & "\" & oRow.MemberName & ".idw", True)
		Next
	End If
End Sub

 

0 Likes
Message 11 of 27

dparmarF6BDE
Enthusiast
Enthusiast

Hello @A.Acheson ,
this is in regards with the error I was getting.
The error I think might be here because I cant generate files from ipart members. I have now idea why but I have to search it out, is it because I have ilogic rules in the ipart members? or there might be another reason? in your experience?

Thanks!

 

 

0 Likes
Message 12 of 27

A.Acheson
Mentor
Mentor

Hi @dparmarF6BDE 

 

There shouldn't be any rules in the ipart factory. Any rules you run should be  external rules and apply only to the factory document. If you leave internal rules in the ipart factory they will be pushed to the ipart member which are read only and will cause errors. 

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

dparmarF6BDE
Enthusiast
Enthusiast

Hello @A.Acheson , 
yes you are right! it is giving me an error while running with rule.  Another point on that is , the script that you gave to me updates and changes the model state in drawing. when I select the active factory member option this rule is not working. Displaying this error. 

dparmarF6BDE_2-1687873300947.png

 

 

dparmarF6BDE_1-1687872582212.png

I marked the line 11 in this script so is there any way we can change the members in the part itself and I can check the "active factory member" in the list so the drawing will get updated as per the current active member in the part. 
if this is possible, it will solve many update issue for me. Right now any updates in the part is not really reflecting in the drawing. 

So basically, what I want to achieve here is 
1).Update model state in the Ipart factory Document itself
2).Then update the drawing so it will capture the current "active factory member" and update all the views
3).Then export idw and dxf files as usual on given location.

Thank you for your time again!



Sub Main

	Dim oDrawing As DrawingDocument = ThisApplication.ActiveDocument
	Dim oPath As String = "C:\Workspace\HS" 'Folder to save the drawings
	Dim oFactory As iPartFactory
	
	
	
	For Each oView As DrawingView In oDrawing.ActiveSheet.DrawingViews
		Dim oDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
		oFactory = oDoc.ComponentDefinition.iPartMember.ParentFactory
		Exit For
	Next
	
	If oFactory Is Nothing = False Then
		For Each oRow As iPartTableRow In oFactory.TableRows
			For Each oView In oDrawing.ActiveSheet.DrawingViews
				If oView.ActiveMemberName <> oRow.MemberName Then oView.ActiveMemberName = oRow.MemberName
				oDrawing.Update
				Do While oView.IsUpdateComplete = False
					Call ThisApplication.UserInterfaceManager.DoEvents
				Loop
			Next
			oDrawing.SaveAs(oPath & "\" & oRow.MemberName & ".idw", True)
			
		Next
	End If
End Sub



 

 

0 Likes
Message 14 of 27

A.Acheson
Mentor
Mentor

Hi @dparmarF6BDE 

 

So I tested the code and it is working exactly as expected. It will loop through the drawing, change the member then save the drawing. Here is the output for the file path before saving the drawing. You will not want to select the active member as this will tie the view to the factory. Select member (row 1) in the drawing then run the script.  Maybe also check that a member is placed on the drawing and not the factory document. 

 

Dim pathWoExt As String = oPath & "\" & oRow.MemberName
Logger.Info(pathWoExt)

AAcheson_0-1687899342380.png

 

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

dparmarF6BDE
Enthusiast
Enthusiast

Thank you very much @A.Acheson ,
this worked perfectly, after I shifted my parameters to the ipart excel sheet rather than ilogic script as you mentioned. 
Now I am trying to generate the dimension in the drawing view, just the overall dimension.
There is something wrong in this script it is not giving me the expected results. Wondering if you would take a look at your convenience. 🙂

 ' REFERENCE THE FILE THAT IS OPEN RIGHT NOW
 
 Dim oDRAWDOC As DrawingDocument
  oDRAWDOC = ThisApplication.ActiveDocument
 
 ' REFERENCE THE ACTIVE SHEET
 Dim oSHEET As Sheet
  oSHEET = oDRAWDOC.ActiveSheet
 
 ' REFERENCE THE VIEW WE WANT
 Dim oVIEW As DrawingView
 oVIEW = oSHEET.DrawingViews.ITEM(1)
 
 ' REFERENCE THE MODEL ON THAT SHEET
 Dim oMODELDOC As Document
  oMODELDOC = oVIEW.ReferencedDocumentDescriptor.ReferencedDocument
 
 ' create a shortcut to the general dimensions on the sheet
 Dim oGENERALDIMS As GeneralDimensions
  oGENERALDIMS = oSHEET.DrawingDimensions.GeneralDimensions

' FIND EDGE LEFT ON THE MODEL
Dim LEFTEDGE As Edge
 oOBJECTS = oMODELDOC.AttributeManager.FindObjects("*", "*", "LEFT")
'If oOBJECTS.Count > 0 Then
     LEFTEDGE = oOBJECTS.Item(1)
    ' Handle the case when no item is found
    ' You may display an error message or perform alternative actions
'End If

' FIND RIGHTNEDGE ON THE MODEL
Dim RIGHTEDGE As Edge
 oOBJECTS = oMODELDOC.AttributeManager.FindObjects("*", "*", "RIGHT")
'If oOBJECTS.Count > 0 Then
     RIGHTEDGE = oOBJECTS.Item(1)
    ' Handle the case when no item is found
    ' You may display an error message or perform alternative actions
'End If

' PROMOTE TO A DRAWING CURVE ON THE VIEW
Dim aoDRAWCURVE1 As DrawingCurve
 oDRAWVIEWCURVES = oVIEW.DrawingCurves(LEFTEDGE)
'If oDRAWVIEWCURVES.Count > 0 Then
     aoDRAWCURVE1 = oDRAWVIEWCURVES.Item(1)
    ' Handle the case when no item is found
    ' You may display an error message or perform alternative actions
'End If
Dim aoDRAWCURVE2 As DrawingCurve
 oDRAWVIEWCURVES = oVIEW.DrawingCurves(RIGHTEDGE)
 aoDRAWCURVE2 = oDRAWVIEWCURVES.Item(1)

' PROMOTE TO A GEOMETRY ON THE SHEET FOR DIMS
Dim GI1 As GeometryIntent
 GI1 = oSHEET.CreateGeometryIntent(aoDRAWCURVE1)

Dim GI2 As GeometryIntent
 GI2 = oSHEET.CreateGeometryIntent(aoDRAWCURVE2)

' CREATE A POINT FOR THE TEXT

Dim DIMTEXT As Point2d
Dim XPOS As Double
Dim YPOS As Double

XPOS = oVIEW.Left + (oVIEW.Width / 2)
YPOS = oVIEW.Top + 0.5

 DIMTEXT = ThisApplication.TransientGeometry.CreatePoint2d(XPOS, YPOS)

' CREATE THE DIMENSION!
Dim oDIMLENGTH As GeneralDimensions
 oDIMLENGTH = oGENERALDIMS.AddLinear(DIMTEXT,GI1,GI2)


 

0 Likes
Message 16 of 27

A.Acheson
Mentor
Mentor
Accepted solution

I think I know the issue here the attributes are stored in the ipart factory and not the member. See this article. What will need to happen is to reference the face/edge in the ipart factory that has the attribute,  store this as a variable then loop through the ipart member faces/edges and find the matching geometry. Luckily I did this a few months ago and found that article. This topic deserves a forum post in itself.

 

In addition  you might consider changing the original post title as model states will be mis-leading as your only working with iparts which are referred to as members in the inventor world.

 

 

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

dparmarF6BDE
Enthusiast
Enthusiast

Hello @A.Acheson ,
Hope you are doing well, the script works just perfect, but sometimes due to some reason it keeps aborting the dxf generation, typically after creating 1000-1200 numbers of dxfs. so is there any way we can tweak the script so that it will start making the dxfs from the current selected member in the drawing view. so I can resume the process from where it broke instead of generating from the very beginning of the members list.

thank you!

Sub Main

	Dim oDrawing As DrawingDocument = ThisApplication.ActiveDocument
	Dim oPath As String = "C\TRIAL" 'Folder to save the drawings
	Dim oFactory As iPartFactory
	
	
	
	For Each oView As DrawingView In oDrawing.ActiveSheet.DrawingViews
		Dim oDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
		oFactory = oDoc.ComponentDefinition.iPartMember.ParentFactory
		Exit For
	Next
	
	If oFactory Is Nothing = False Then
		For Each oRow As iPartTableRow In oFactory.TableRows
			For Each oView In oDrawing.ActiveSheet.DrawingViews
				If oView.ActiveMemberName <> oRow.MemberName Then oView.ActiveMemberName = oRow.MemberName
				oDrawing.Update
' Get the DXF translator Add-In.
Dim DXFAddIn As TranslatorAddIn
DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
'Set a reference to the active document (the document to be published).
Dim oDocument As Document
oDocument = ThisApplication.ActiveDocument
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
' Create a NameValueMap object
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
' Create a DataMedium object
Dim oDataMedium As DataMedium
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
' Check whether the translator has 'SaveCopyAs' options
If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
Dim strIniFile As String
strIniFile = "C:\temp\dxfout.ini"
' Create the name-value that specifies the ini file to use.
oOptions.Value("Export_Acad_IniFile") = strIniFile
End If
'Set the destination file name
Dim dxfFileName As String = oPath & "\DXF\" & oRow.MemberName & ".dxf"
oDataMedium.FileName = dxfFileName


iLogicVb.RunRule("CENTERMARK REMOVAL")
iLogicVb.RunRule("CENTERMARK")
iLogicVb.RunRule("FIXED SCALE")
iLogicVb.RunRule("POSITION")

'Publish document.
DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)	
oDrawing.Update
				Do While oView.IsUpdateComplete = False
					Call ThisApplication.UserInterfaceManager.DoEvents
				Loop
			Next
			
			oDrawing.SaveAs(oPath & "\IDW\" & oRow.MemberName & ".idw", True)
			'oDrawing.SaveAs(oPath & "\PDF\" & oRow.MemberName & ".pdf", True)
			'oDrawing.SaveAs(oPath & "\PDF\" & oRow.MemberName & ".pdf", True)
		Next
	End If
End Sub

dparmarF6BDE_0-1688673167627.png

 

 

0 Likes
Message 18 of 27

A.Acheson
Mentor
Mentor

Hi @dparmarF6BDE 

Try this approach. Input box for the start member name, inside the loop check the member name against the start member name, if it doesn't match go to next row when it finally matches, set start member name variable to nothing then the next row the start condition is bypassed and the loop continues as normal.   

 

Dim memberName As String = InputBox("Enter the Membername you wish to Start the Loop", "iLogic", "A000000000") 
	If Not oRow.MemberName = memberName AndAlso  Not memberName Is Nothing Then Continue For
	memberName = Nothing

 

 

 

Sub Main

	Dim oDrawing As DrawingDocument = ThisApplication.ActiveDocument
	Dim oPath As String = "C\TRIAL" 'Folder to save the drawings
	Dim oFactory As iPartFactory 

	For Each oView As DrawingView In oDrawing.ActiveSheet.DrawingViews
		Dim oDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
		oFactory = oDoc.ComponentDefinition.iPartMember.ParentFactory
		Exit For
	Next
	
	Dim memberName As String = InputBox("Enter the Membername you wish to Start the Loop", "iLogic", "A000000000") 
	
	If oFactory Is Nothing = False Then
		For Each oRow As iPartTableRow In oFactory.TableRows
				If Not oRow.MemberName = memberName AndAlso  Not memberName Is Nothing Then Continue For
				memberName = Nothing
			
			For Each oView In oDrawing.ActiveSheet.DrawingViews
				If oView.ActiveMemberName <> oRow.MemberName Then oView.ActiveMemberName = oRow.MemberName
				oDrawing.Update
				
				' Get the DXF translator Add-In.
				Dim DXFAddIn As TranslatorAddIn
				DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
				
				'Set a reference to the active document (the document to be published).
				Dim oDocument As Document
				oDocument = ThisApplication.ActiveDocument
				
				Dim oContext As TranslationContext
				oContext = ThisApplication.TransientObjects.CreateTranslationContext
				oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
				
				' Create a NameValueMap object
				Dim oOptions As NameValueMap
				oOptions = ThisApplication.TransientObjects.CreateNameValueMap
				
				' Create a DataMedium object
				Dim oDataMedium As DataMedium
				oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
				
				' Check whether the translator has 'SaveCopyAs' options
				If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
					Dim strIniFile As String
					strIniFile = "C:\temp\dxfout.ini"
					' Create the name-value that specifies the ini file to use.
					oOptions.Value("Export_Acad_IniFile") = strIniFile
				End If
				
				'Set the destination file name
				Dim dxfFileName As String = oPath & "\DXF\" & oRow.MemberName & ".dxf"
				oDataMedium.FileName = dxfFileName
				
				
				iLogicVb.RunRule("CENTERMARK REMOVAL")
				iLogicVb.RunRule("CENTERMARK")
				iLogicVb.RunRule("FIXED SCALE")
				iLogicVb.RunRule("POSITION")
				
				'Publish document.
				DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)	
				oDrawing.Update
				
				Do While oView.IsUpdateComplete = False
					Call ThisApplication.UserInterfaceManager.DoEvents
				Loop
			Next
			
			oDrawing.SaveAs(oPath & "\IDW\" & oRow.MemberName & ".idw", True)
			oDrawing.SaveAs(oPath & "\PDF\" & oRow.MemberName & ".pdf", True)
			oDrawing.SaveAs(oPath & "\PDF\" & oRow.MemberName & ".pdf", True)
		Next
	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 19 of 27

dparmarF6BDE
Enthusiast
Enthusiast

HI @A.Acheson ,
Thank you for your solution, however the line 21 is giving an unspecified error , the loop is starting the way I want but after exporting dxf for first member( name entered in input box), it  stopped working.  

Sub Main

	Dim oDrawing As DrawingDocument = ThisApplication.ActiveDocument
	Dim oPath As String = "C:\TRIAL" 'Folder to save the drawings
	Dim oFactory As iPartFactory 

	For Each oView As DrawingView In oDrawing.ActiveSheet.DrawingViews
		Dim oDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
		oFactory = oDoc.ComponentDefinition.iPartMember.ParentFactory
		Exit For
	Next
	
	Dim memberName As String = InputBox("Enter the Membername you wish to Start the Loop", "iLogic", "123123") 
	
	If oFactory Is Nothing = False Then
		For Each oRow As iPartTableRow In oFactory.TableRows
				If Not oRow.MemberName = memberName AndAlso  Not memberName Is Nothing Then Continue For
				memberName = Nothing
			
			For Each oView In oDrawing.ActiveSheet.DrawingViews
				If oView.ActiveMemberName <> oRow.MemberName Then oView.ActiveMemberName = oRow.MemberName
				oDrawing.Update
				
				' Get the DXF translator Add-In.
				Dim DXFAddIn As TranslatorAddIn
				DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
				
				'Set a reference to the active document (the document to be published).
				Dim oDocument As Document
				oDocument = ThisApplication.ActiveDocument
				
				Dim oContext As TranslationContext
				oContext = ThisApplication.TransientObjects.CreateTranslationContext
				oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
				
				' Create a NameValueMap object
				Dim oOptions As NameValueMap
				oOptions = ThisApplication.TransientObjects.CreateNameValueMap
				
				' Create a DataMedium object
				Dim oDataMedium As DataMedium
				oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
				
				' Check whether the translator has 'SaveCopyAs' options
				If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
					Dim strIniFile As String
					strIniFile = "C:\temp\dxfout.ini"
					' Create the name-value that specifies the ini file to use.
					oOptions.Value("Export_Acad_IniFile") = strIniFile
				End If
				
				'Set the destination file name
				Dim dxfFileName As String = oPath & "\" & oRow.MemberName & ".dxf"
				oDataMedium.FileName = dxfFileName
				
				
				iLogicVb.RunRule("CENTERMARK REMOVAL")
				iLogicVb.RunRule("CENTERMARK")
				iLogicVb.RunRule("FIXED SCALE")
				iLogicVb.RunRule("POSITION")
				
				'Publish document.
				DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)	
				oDrawing.Update
				
				Do While oView.IsUpdateComplete = False
					Call ThisApplication.UserInterfaceManager.DoEvents
				Loop
			Next
			
			'oDrawing.SaveAs(oPath & "\IDW\" & oRow.MemberName & ".idw", True)
			'oDrawing.SaveAs(oPath & "\PDF\" & oRow.MemberName & ".pdf", True)
		Next
	End If
End Sub

I have highlighted the line which was causing the error.
thanks again! 

0 Likes
Message 20 of 27

A.Acheson
Mentor
Mentor

Hi @dparmarF6BDE 

Can you switch off all the actions like saving and exporting and just place this line in under oDrawing.Update

 

Logger.Info(oRow.Index)

 This will give the index number and you can see if the loop is working correctly. I am assuming you can activate the next ipart manually on the drawing and there is no issue? 

It might also be better practice to bring the do loop pausing for view update to just after the member is changed. This way the rule gives time for the view to change and update before trying to export the dxf. Perhaps this was the issue in the first place as it may have tripped itself up. Where it is now is currently doing nothing for the process as all the operations have allready being done to the drawing. 

 

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