- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I have a small issue with my code. This code is executed before each saving of an ipt, iam, ipn, or idw file, depending on conditions such as "isDrawing().
The code should execute differently depending on the type of file we are dealing with.
However, when the script is launched from an idw, and the script will modify the ipt or iam file via the function "copyIpropValueFromidwToIptIamIpn()", the ipt or iam file is also modified, and therefore the code also executes for it.
The problem is that the function "isDrawing()" always returns "true" at the time of saving the ipt or iam, when it should not be the case.
I suppose this is because the original script call is made from the idw, and ThisApplication.ActiveDocumentType always reports this idw.
I also tried to use the line "ThisApplication.ActiveEditDocument.DocumentType", but without success.
I hope I made myself clear.
In summary, "isDrawing()" always returns "true" even if the script concerns an ipt or iam.
Can you help me please?
Thank you
Sébastien
Sub main() 'This Sub is automatically called for each ipt, iam, idw, or ipn just before saving time with trigger event.
' Check if the active document is a drawing
If isDrawing() Then
MsgBox(isDrawing() & " " & ThisDoc.FileName)
'Call restorIpropCustom
'Call FindDepartementIfNotExist
'Call copyDataFromTitleBlockToIdwIprop
Call copyIpropValueFromidwToIptIamIpn
'Call replaceTitleBloc2
End If
If isIptIamIpn() Then
MsgBox(isIptIamIpn() & " " & ThisDoc.FileName)
End If
End Sub
' Function to check if the active document is a drawing
Function isDrawing()
If ThisApplication.ActiveDocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
isDrawing = True
Else
isDrawing = False
End If
End Function
' Function to check if the active document is a drawing
Function isDrawing2() As Boolean
Try
If ThisApplication.ActiveEditDocument.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
' If the active document is a drawing
EstEnModeMiseEnPlan = True
Else
' If the active document is not a drawing
EstEnModeMiseEnPlan = False
End If
Catch ex As Exception
MsgBox("An error occurred: " & ex.Message)
EstEnModeMiseEnPlan = False
End Try
End Function
' Function to check if the active document is an assembly, part, or presentation
Function isIptIamIpn()
If ThisApplication.ActiveDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Or ThisApplication.ActiveDocumentType = DocumentTypeEnum.kPartDocumentObject Or ThisApplication.ActiveDocumentType = DocumentTypeEnum.kPresentationDocumentObject Then
isIptIamIpn = True
Else
isIptIamIpn = False
End If
End Function
Function copyIpropValueFromidwToIptIamIpn
Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
If oDDoc.AllReferencedDocuments.Count > 0 Then
'a Drawing can contain more than one 'Model' document, but the first is always used
Dim oMDoc As Document = oDDoc.AllReferencedDocuments.Item(1)
If Not iProperties.Value("Project", "Description") = oMDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value Then
oMDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value = iProperties.Value("Project", "Description")
End If
End If
End Function
Solved! Go to Solution.