Check if model haven't description from drawing then add description in drawing and copy to model

Check if model haven't description from drawing then add description in drawing and copy to model

Anonymous
Not applicable
430 Views
1 Reply
Message 1 of 2

Check if model haven't description from drawing then add description in drawing and copy to model

Anonymous
Not applicable

Hi i've made this rules to do the description job.

 

The rule work well to add description in drawing and copy to model but i don't know why the description of model from drawing doesn't work very well. Can someone help me please?

Thank you

 

Dim oDDoc As DrawingDocument = ThisDrawing.Document

'Getting the description of the active drawing document, without checking if it is empty
Dim oDrawingDesc As String = iProperties.Value("Project", "Description")

'Getting the active sheet of the active drawing
Dim oSheet As Sheet = oDDoc.ActiveSheet

'Getting the first view that was placed into the drawing (you could specify the drawings name here too inside "" marks)
Dim oView As DrawingView = oSheet.DrawingViews.Item(1)

'Getting the document being represented within the view
Dim oVDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument

'ThisDoc.Launch(oVDoc.FullFileName)
'Getting the model documents description iProperty value the shorter way, without checking if it is empty
Dim oVDesc As String = iProperties.Value(oVDoc, "Project", "Description")


If oVDesc = "" Then
    myparam = InputBox("Manca la descrizione", "Descrizione mancante", "")
     iProperties.Value("Project", "Description") = myparam
     InventorVb.DocumentUpdate()
     
End If

'System.Threading.Thread.CurrentThread.Sleep(1000)
InventorVb.DocumentUpdate()
iLogicVb.RunExternalRule("provissima")

 

second rule triggered at the end of first

Sub Main()

    If Not ThisApplication.ActiveDocument.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
        MessageBox.Show("Current document is not drawing docuemnt", "Inventor")
        Exit Sub
    End If
    Dim value_List As List(Of String) = New List(Of String)

    value_List.Add (iProperties.Value("Project", "Description"))

    Dim oDoc As Document
    oDoc = ThisDrawing.ModelDocument

    If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
        
        Update_Properties(oDoc,  value_List)
        
        Dim oAsyDoc As AssemblyDocument
        oAsyDoc = oDoc
         
        Dim oReferDoc As Document
        Dim occ As ComponentOccurrence
        Dim oDef As AssemblyComponentDefinition
        oDef = oAsyDoc.ComponentDefinition

        For Each occ In oDef.Occurrences
            If occ.SubOccurrences.Count = 0 Then
                oReferDoc = occ.ReferencedDocumentDescriptor.ReferencedDocument
                Update_Properties(oReferDoc, value_List)
            Else
                oReferDoc = occ.ReferencedDocumentDescriptor.ReferencedDocument
                Update_Properties(oReferDoc,   value_List)
                processAllSubOcc(occ,  value_List)
            End If
        Next
        
    Else If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
        Update_Properties(oDoc, value_List)
    End If

End Sub

Private Sub processAllSubOcc(ByVal oCompOcc As ComponentOccurrence , value_List As List(Of String))
    
    Dim oSubCompOcc As ComponentOccurrence
    Dim oReferDoc As Document
    For Each oSubCompOcc In oCompOcc.SubOccurrences
        If oSubCompOcc.SubOccurrences.Count = 0 Then
            oReferDoc = oSubCompOcc.ReferencedDocumentDescriptor.ReferencedDocument
            Update_Properties(oReferDoc,value_List)
        Else
            oReferDoc = oSubCompOcc.ReferencedDocumentDescriptor.ReferencedDocument
            Update_Properties(oReferDoc ,value_List)
            Call processAllSubOcc(oSubCompOcc, value_List)
        End If
    Next
    
End Sub

Sub Update_Properties(oDoc As Document,   value_List As List(Of String))
    
    oDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value = value_List.Item(0)
    oDoc.Save()
	InventorVb.DocumentUpdate()
    
End Sub
0 Likes
Accepted solutions (1)
431 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Accepted solution

I've solved by myself.
If someone need it

 

Dim oDoc As DrawingDocument = ThisDoc.Document
Dim oSheet As Sheet = oDoc.ActiveSheet
Dim oView As DrawingView = oSheet.DrawingViews.Item(1)


If oView Is Nothing Then Exit Sub

oModelDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument

'Get the properties of the reference model of the view 
oDescripProp = oModelDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value  
 

If oDescripProp = "" Then

	myparam = InputBox("Manca la descrizione", "Descrizione mancante", "")
    iProperties.Value("Project", "Description") = myparam
	oModelDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value = myparam
End If

     InventorVb.DocumentUpdate()

 


0 Likes