iLOGIC to change properties on top level Asm components only

iLOGIC to change properties on top level Asm components only

JamesNordgren
Advocate Advocate
2,640 Views
2 Replies
Message 1 of 3

iLOGIC to change properties on top level Asm components only

JamesNordgren
Advocate
Advocate

I have some code that sets a couple iproperty values of assemblt components based on the components' File Name.

It produces the desired result, but runs way too slow since it is looking at every file in the assemblies referenced document set.

 

How can I modify this to only look at first-level assembly occurrences?  My code pasted below:

'------------------------------------------------------------------------------------------------------'Set all CONFIGURED components in assembly to have designer initials as Author and Designer iPropertiesopenDoc = ThisDoc.Document
docFile = ThisDoc.Document
Dim docFName As String
Dim FNamePos As Long
comps = docFile.ComponentDefinition.Occurrences
names = New List(Of String)
For Each docFile In openDoc.AllReferencedDocuments
    'Find position in full filename path string where component filename begins    FNamePos = InStrRev(docFile.FullFileName, "\", - 1)
    'Strip off filename path string and set docFName to just the component's file name    docFName = Mid(docFile.FullFileName, FNamePos + 1, Len(docFile.FullFileName) - FNamePos)
    'Check if first 5 characters of docFName is equal to Job Number string:     If Left(docFName,5) = Parameter("CONFIG FILE", "sJobNumber") Then
        iProperties.Value(docFName, "Project", "Designer") = Parameter("CONFIG FILE", "sDesignerInitials")
        iProperties.Value(docFName, "Summary", "Author") = Parameter("CONFIG FILE", "sDesignerInitials")
    Else
    'MessageBox.Show(docFName, "Title")    End If
Next

 

I am sure it is a simple task:  I just cant find an example of operating on filenames using the ComponentDefinition methods.

 

Thanks to anyone who can help!

 

James

0 Likes
Accepted solutions (1)
2,641 Views
2 Replies
Replies (2)
Message 2 of 3

wayne.brill
Collaborator
Collaborator
Accepted solution

Hi James,

 

Here is another approach to try. This example uses the occurrences collection of the assembly instead of the referenced documents. You can get the document from each occurrence. The SubOccurrences.Count can tell you if the occurrence is a sub assembly.  

 

Here is some code I tested in an iLogic rule. It shows the idea but it will need to be adjusted for your documents. It adds the name to the list of strings to avoid adding the iProperties multiple times. The logic does not seem complete however. Wouldn't this line always be true? (I assume there is an occurrence named "Config File" in the top assembly)

 ' If Left(docFName,5) = Parameter("CONFIG FILE", "sJobNumber") Then

 

docFile = ThisDoc.Document

 

Dim docFName As String

Dim FNamePos As Long

 

Dim comps as ComponentOccurrences

comps = docFile.ComponentDefinition.Occurrences

 

names = New List(Of String)

 

Dim comp As ComponentOccurrence

For Each comp In comps

    'MessageBox.Show(comp.Name)

    ' Check if the occurrence is a sub assembly

    If comp.SubOccurrences.count > 1 Then

        'MessageBox.Show(comp.Name)

        'Get the Document from the occurrence

        docFile = comp.definition.Document

         'Find position in full filename path string where component filename begins   

         FNamePos = InStrRev(docFile.FullFileName, "\", - 1)

        'Strip off filename path string and set docFName to just the component's file name  

         docFName = Mid(docFile.FullFileName, FNamePos + 1, Len(docFile.FullFileName) - FNamePos)

        'MessageBox.Show("before If Not contains docFName")

        If Not names.contains(docFName) Then

            names.add(docFName)

            MessageBox.Show(names(0))

       

        ' If Left(docFName,5) = Parameter("CONFIG FILE2:1", "sJobNumber") Then

         If Parameter("CONFIG FILE2:1", "sJobNumber") = 1234 Then

              iProperties.Value(docFName, "Project", "Designer") = Parameter("CONFIG FILE2:1", "sDesignerInitials")

            iProperties.Value(docFName, "Summary", "Author") = Parameter("CONFIG FILE2:1", "sDesignerInitials")

        Else

        'MessageBox.Show(docFName, "Title")   

        End If ' Parameter = 1234

        End If ' names does not contain document name

    End If ' count >1

Next

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 3

JamesNordgren
Advocate
Advocate

Hi Wayne,

Thanks for the thoughtful response.    You said: 

The logic does not seem complete however. Wouldn't this line always be true? (I assume there is an occurrence named "Config File" in the top assembly)

 ' If Left(docFName,5) = Parameter("CONFIG FILE", "sJobNumber") Then


For the sake of clarifying what this is a solution for, let me restate my objective more clearly.

I just wanted to set iProperties on 1st Level Occurrences in my assembly.  I do not care if the occurrence is a part or assembly.  The Assembly is made up of a mix of custom iLogic driven parts and Standard Components from our library.  I only wanted to set the properties on the custom parts, not the Standard library parts, so that is why I look at the 1st 5 characters of the file name.  

You provided me the one little piece I was missing, which was docFile = comp.definition.Document.

I just couldnt find a reference for how to access the document's file name from the occurrence.

 

Now it works great and runs in about 3 seconds instead of 30!  The simplified and now functioning code is pasted below.

 

'Set all CONFIGURED components in assembly to have designer initials as Author and Designer iProperties
'openDoc = ThisDoc.Document
docFile = ThisDoc.Document
Dim docFName As String
Dim FNamePos As Long
comps = docFile.ComponentDefinition.Occurrences
names = New List(Of String)
Dim comp As ComponentOccurrence
For Each comp In comps
	'MessageBox.Show(comp.Name,"SETTING PROPERTIES")
	names.Add(comp.Name)		'Create List of all Top-Level Occurrence names in the assembly
	docFile = comp.definition.Document
	'Find position in full filename path string where component filename begins
	FNamePos = InStrRev(docFile.FullFileName, "\", - 1)
	'Strip off filename path string and set docFName to just the component's file name
	docFName = Mid(docFile.FullFileName, FNamePos + 1, Len(docFile.FullFileName) - FNamePos)
	'Check if first 5 characters of docFName is equal to Job Number string: 
	If Left(docFName,5) = Parameter("CONFIG FILE", "sJobNumber") Then
		iProperties.Value(docFName, "Project", "Designer") = Parameter("CONFIG FILE", "sDesignerInitials")
		iProperties.Value(docFName, "Summary", "Author") = Parameter("CONFIG FILE", "sDesignerInitials")
	Else
	'MessageBox.Show(docFName, "PROPERTIES NOT BEING SET")
	End If
Next

MultiValue.List("sOccurrenceList") = names

 

 

0 Likes