Hi
This dim exp code is running into an error. trying to move all dims from inventor idw to csv
Error on Line 41 : 'kNoUnits' is not a member of 'Inventor.UnitsTypeEnum'.
Code :
Imports Inventor
Imports System.IO
Sub Main()
' Get the active part document
Dim oDoc As PartDocument
oDoc = TryCast(ThisApplication.ActiveDocument, PartDocument)
' Check if the active document is a part
If oDoc Is Nothing Then
MessageBox.Show("This rule is intended for use in a part document.")
Exit Sub
End If
' Define the file path for the CSV file
Dim csvFilePath As String = "C:\Temp\Dimensions.csv"
' Open or create the CSV file
Using sw As StreamWriter = New StreamWriter(csvFilePath)
' Write the header
sw.WriteLine("Dimension Name,Dimension Value")
' Find the sweep feature, regardless of name
Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
Dim oSweep As SweepFeature = Nothing
' Iterate through all features to find the first sweep feature
For Each oFeature As PartFeature In oDef.Features
If TypeOf oFeature Is SweepFeature Then
oSweep = TryCast(oFeature, SweepFeature)
Exit For
End If
Next
If oSweep IsNot Nothing Then
' If the sweep feature is active, proceed
If Feature.IsActive(oSweep.Name) Then
' Loop through all parameters in the sweep feature's profile
For Each oParam As Parameter In oSweep.Profile.Parameters
' Check if the parameter represents a dimension
If oParam.UnitType = UnitsTypeEnum.kNoUnits Then
Dim dimName As String = oParam.Name
Dim dimValue As String = oParam.Value
' Write dimension name and value to the CSV file
sw.WriteLine(dimName & "," & dimValue)
End If
Next
Else
' Do something if the sweep feature is not active
End If
Else
MessageBox.Show("Sweep feature not found in the part.")
End If
End Using
' Inform the user
MessageBox.Show("Dimensions exported to CSV file at " & csvFilePath)
End Sub
Hi @CAD-One
"kNoUnits" according to UnitsTypeEnum Enumerator list here is not a member of UnitsTypeEnum Enumerator. You will need to remove the if statement or change to Enumerator that is available.
@A.Acheson Thank you. I tried that and it didn't help.
revised the code, but still running into issues. See the error at the end.
Sub Main()
' Get the active drawing document
Dim oDoc As DrawingDocument
oDoc = TryCast(ThisApplication.ActiveDocument, DrawingDocument)
' Check if the active document is a drawing
If oDoc Is Nothing Then
MsgBox("This rule is intended for use in a drawing document.")
Exit Sub
End If
' Define the file path for the CSV file
Dim csvFilePath As String = "C:\Temp\Dimensions.csv"
' Open or create the CSV file
Using sw As System.IO.StreamWriter = New System.IO.StreamWriter(csvFilePath)
' Write the header
sw.WriteLine("Dimension Name,Dimension Value")
' Loop through all dimensions in the active drawing
For Each oDim As DrawingDimension In oDoc.ActiveSheet.DrawingDimensions
' Use dimension text as the name
Dim dimName As String = oDim.Text
Dim dimValue As String = oDim.Value
' Write dimension name and value to the CSV file
sw.WriteLine(dimName & "," & dimValue)
Next
End Using
' Inform the user
MsgBox("Dimensions exported to CSV file at " & csvFilePath)
End Sub
error : Unable to cast COM object of type 'System.__ComObject' to class type 'System.String'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
The issue I believe is here
Dim dimName As String = oDim.Text
oDim.Text is not type of string but rather type of DimensionText, this should be.
Dim dimName As String = oDim.Text.Text
And here is the API help for dimension text object.
And also this one here
Dim dimValue As String = oDim.Value
oDim.Value property doesn't exist see API help here.
Dim dimValue As String = oDim.ModelValue
Can't find what you're looking for? Ask the community or share your knowledge.