Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create Custom iProperties & Parameters for Sub-Assemblies

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Preston_Reed
438 Views, 4 Replies

Create Custom iProperties & Parameters for Sub-Assemblies

Hello, I am trying to create a rule that will create custom iProperties & User Parameters for sub-assemblies & their piece parts.  The intention is to make the custom iProperties as they fill in title block info.  Also I am working on making a tool that will replace design assistant for design copy type projects.  I have the majority of it working besides being able to create custom iProperties and User Parameters for the sub-assemblies and their piece parts.  Any help would be appreatiated.  Here is an example of what I was trying to do, this doesn't do anything, I went about it through oOccurences too but that wouldn't work, I don't think its allowing me to access ComponentDefinition though Occurences.   

 

 

 

    ' Get the active assembly.
    Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
    ' Get all of the referenced documents.
    Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments
	
	
    ' Iterate through the list of documents.
    For Each oRefDoc As Document In oRefDocs
		'Skipping any purchased or mfg parts / any parts that are not accessable 
		If oRefDoc.IsModifiable() = True AndAlso oRefDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then	

			oSubAsmParameter = oRefDoc.ComponentDefinition.Parameters.UserParameters
			'Creating sub-assembly user parameters
			oParameter = oSubAsmParameter.AddByValue("CUSTOMER NAME-1", "", UnitsTypeEnum.kTextUnits)
			oParameter = oSubAsmParameter.AddByValue("CUSTOMER PO#", "", UnitsTypeEnum.kTextUnits)
			oParameter = oSubAsmParameter.AddByValue("END USER-1", "", UnitsTypeEnum.kTextUnits)
			oParameter = oSubAsmParameter.AddByValue("PARENT PRODUCT#", "", UnitsTypeEnum.kTextUnits)
			oParameter = oSubAsmParameter.AddByValue("PROJECT#", "", UnitsTypeEnum.kTextUnits)
			oParameter = oSubAsmParameter.AddByValue("SO#", "", UnitsTypeEnum.kTextUnits)
			oParameter = oSubAsmParameter.AddByValue("WORK ORDER#", "", UnitsTypeEnum.kTextUnits)
		Else
		End If 
	Next
	
	
			
4 REPLIES 4
Message 2 of 5

This part of old VBA code to get Properties from active assembly and copy them to all childs.

The important part is recursive processAllSubFiles.

Private Sub SetCmdBtn_Click()
'Dim Temp(1, 4)
'Temp(0, 0) = TitleBox
'Temp(0, 1) = CompanyBox
'Temp(0, 2) = RevBox
'Temp(0, 3) = ProjectBox
'HistoryList.List() = Temp
'HistoryList.ListIndex = 0
Dim oDoc As Inventor.Document
Dim oPropsets As PropertySets
Dim oPropSet As PropertySet
Dim oRefFiles As DocumentsEnumerator
Dim oRefFile As Document
Dim iLeafNodes As Long
Dim iSubAssemblies As Long

Set oDoc = ThisApplication.ActiveDocument
Set oRefFile = oDoc
If oRefFile.IsModifiable Then
  Set oPropsets = oRefFile.PropertySets
  Set oPropSet = oPropsets.Item("Design Tracking Properties")
  If (oPropSet.Item("Project").value <> "Common") _
     And (oPropSet.Item("Project").value <> "Purchase") _
     And (oPropSet.Item("Project").value <> "Hardware") Then
    Set oPropSet = oPropsets.Item("Summary Information")
    oPropSet.Item("Title").value = TitleBox
    oPropSet.Item("Revision Number").value = RevBox
    oPropSet.Item("Author").value = AuthorBox
    Set oPropSet = oPropsets.Item("Document Summary Information")
    oPropSet.Item("Company").value = CompanyBox
    Set oPropSet = oPropsets.Item("Design Tracking Properties")
    oPropSet.Item("Project").value = ProjectBox
    oPropSet.Item("Designer").value = DesignerBox
  End If
End If

' Get all occurrences from component definition for Assembly document
Set oRefFiles = oDoc.ReferencedDocuments
processAllSubFiles oRefFiles
End Sub

Private Sub processAllSubFiles(ByVal oRefFiles As DocumentsEnumerator)
   
Dim oRefFile As Document
Dim oPropsets As PropertySets
Dim oPropSet As PropertySet

For Each oRefFile In oRefFiles
    If oRefFile.IsModifiable Then
      Set oPropsets = oRefFile.PropertySets
      Set oPropSet = oPropsets.Item("Design Tracking Properties")
      If (oPropSet.Item("Project").value <> "Common") _
          And (oPropSet.Item("Project").value <> "Purchase") _
          And (oPropSet.Item("Project").value <> "Hardware") Then
        Set oPropsets = oRefFile.PropertySets
        Set oPropSet = oPropsets.Item("Summary Information")
        oPropSet.Item("Title").value = TitleBox
        oPropSet.Item("Revision Number").value = RevBox
        oPropSet.Item("Author").value = AuthorBox
        Set oPropSet = oPropsets.Item("Document Summary Information")
        oPropSet.Item("Company").value = CompanyBox
        Set oPropSet = oPropsets.Item("Design Tracking Properties")
        oPropSet.Item("Project").value = ProjectBox
        oPropSet.Item("Designer").value = DesignerBox
      End If
    End If
    If oRefFile.ReferencedFiles.Count > 0 Then
        processAllSubFiles oRefFile.ReferencedFiles
    End If
Next
End Sub

 

Message 3 of 5

Partial VB.Net, different recursive:

  Private Sub BtSet_Click(sender As Object, e As EventArgs) Handles btSet.Click
    SetProperties(OApp.ActiveDocument)
  End Sub

  Private Sub SetProperties(oDoc As Document)
    Dim MCValue As String
    Dim EtchValue As String

    If oDoc.IsModifiable Then
      oPropsets = oDoc.PropertySets
      oPropset = oPropsets.Item("Summary Information")
      If cbTitle.Checked Then
        oPropset.Item("Title").Value = PropCopy.StandardAddInServer.Title
      End If
      If cbRev.Checked Then
        oPropset.Item("Revision Number").Value = PropCopy.StandardAddInServer.Rev
      End If
      If cbAuthor.Checked Then
        oPropset.Item("Author").Value = PropCopy.StandardAddInServer.Author
      End If

      oPropset = oPropsets.Item("Document Summary Information")
      If cbCompany.Checked Then
        oPropset.Item("Company").Value = PropCopy.StandardAddInServer.Company
      End If

      oPropset = oPropsets.Item("Design Tracking Properties")
      If cbProject.Checked Then
        oPropset.Item("Project").Value = PropCopy.StandardAddInServer.Project
      End If
      If cbDesigner.Checked Then
        oPropset.Item("Designer").Value = PropCopy.StandardAddInServer.Designer
      End If

      oPropset = oPropsets.Item("User Defined Properties")
      If cbFinish.Checked Then
        Try
          oPropset.Item("Finish").Value = PropCopy.StandardAddInServer.Finish
        Catch
          oPropset.Add(PropCopy.StandardAddInServer.Finish, "Finish")
        End Try
      End If
      If cbHardness.Checked Then
        Try
          oPropset.Item("Hardness").Value = PropCopy.StandardAddInServer.Hardness
        Catch
          oPropset.Add(PropCopy.StandardAddInServer.Hardness, "Hardness")
        End Try
      End If
      If cbThickness.Checked Then
        Try
          oPropset.Item("Thickness").Value = PropCopy.StandardAddInServer.Thickness
        Catch
          oPropset.Add(PropCopy.StandardAddInServer.Thickness, "Thickness")
        End Try
      End If
      If cbCode.Checked Then
        Try
          oPropset.Item("CODE").Value = PropCopy.StandardAddInServer.Code
        Catch
          oPropset.Add(PropCopy.StandardAddInServer.Code, "CODE")
        End Try
      End If
      If cbMaterialCert.Checked Then
        If MCYesButton.Checked Then
          MCValue = "MTR and Heat Number Required"
        Else
          MCValue = ""
        End If
        Try
          oPropset.Item("Material Cert Required").Value = MCValue
        Catch
          oPropset.Add(MCValue, "Material Cert Required")
        End Try
      End If
      If cbEtch.Checked Then
        If EtchYesButton.Checked Then
          EtchValue = "Etching"
        Else
          EtchValue = ""
        End If
        Try
          oPropset.Item("Etch").Value = EtchValue
        Catch
          oPropset.Add(EtchValue, "Etch")
        End Try
      End If
    End If
    Close()
  End Sub

  Private Sub BtSetAll_Click(sender As Object, e As EventArgs) Handles btSetAll.Click
    Dim oRefFiles As Document

    oDoc = OApp.ActiveDocument
    SetProperties(oDoc)
    For Each oRefFiles In oDoc.AllReferencedDocuments
      If oRefFiles.IsModifiable Then
        SetProperties(oRefFiles)
      End If
    Next
    Close()
  End Sub

 

Message 4 of 5

Thanks for the help, cant get any of this to work though 

Message 5 of 5
Preston_Reed
in reply to: Preston_Reed

Solved for the most part

 

 	' Get the active assembly.
    Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
    ' Get all of the referenced documents.
    Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments
	
    ' Iterate through the list of documents.
    For Each oRefDoc As Document In oRefDocs
		' Skipping any purchased or mfg parts / any parts that are not accessable 
		If oRefDoc.IsModifiable() = True AndAlso oRefDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then	
			Try
				oRefDoc.PropertySets("Inventor User Defined Properties").Item("CUSTOMER NAME-1").Value = ""
				oRefDoc.PropertySets("Inventor User Defined Properties").Item("CUSTOMER PO#").Value = ""
				oRefDoc.PropertySets("Inventor User Defined Properties").Item("END USER-1").Value = ""
				oRefDoc.PropertySets("Inventor User Defined Properties").Item("PARENT PRODUCT#").Value = ""
				oRefDoc.PropertySets("Inventor User Defined Properties").Item("PROJECT#").Value = ""
				oRefDoc.PropertySets("Inventor User Defined Properties").Item("SO#").Value = ""
				oRefDoc.PropertySets("Inventor User Defined Properties").Item("WORK ORDER#").Value = ""
			Catch
		   		oRefDoc.PropertySets("Inventor User Defined Properties").Add("", "CUSTOMER NAME-1")
				oRefDoc.PropertySets("Inventor User Defined Properties").Add("", "CUSTOMER PO#")
				oRefDoc.PropertySets("Inventor User Defined Properties").Add("", "END USER-1")
				oRefDoc.PropertySets("Inventor User Defined Properties").Add("", "PARENT PRODUCT#")
				oRefDoc.PropertySets("Inventor User Defined Properties").Add("", "PROJECT#")
				oRefDoc.PropertySets("Inventor User Defined Properties").Add("", "SO#")
				oRefDoc.PropertySets("Inventor User Defined Properties").Add("", "WORK ORDER#")
		    End Try
		Else
		End If 
	Next
	
	
			

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report