Selected object to Assembly Group

Pioneer
Pioneer

Hi, 

 

I'm trying to put more objects from SelectSet into Assembly Group.

I have an issue, that adding objects to the Group , method AddToGroup requires integer and System.Array.

I'm little bit confused of this. I though that I use items in SelectionSet, but they are COM Objects, which probably needs to be converted to System.Array, but I have no idea how to do this.

 

For k = 1 To MySel.Count

    If MySel.Item(k).Name <> NameGroup Then
        MyAsmGroup.AddToGroup(MyInteger, SelObjArray)
     End If

Next

 

I don't understand what value should represent the variable MyInteger, and also how to put selected objects to SelObjArray.

 

 

Could anyone help me?

 

Thank you

 

Lubos

13 REPLIES

Re: Selected object to Assembly Group

Siemens Phenom Siemens Phenom
Siemens Phenom

Hi,

 

AddToGroup takes two arguments - the number of components you are adding and then the array containing each of those components. So in your example, instead of calling AddToGroup for each selected item, you would instead need to change your loop to add each selected item to an array. After you have populated the array with the selected items, you would call AddToGroup one time using the number of selected items and the array containing the selected items as the arguments.

 

Greg

Re: Selected object to Assembly Group

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

If we look at the definition of the method in Spy for Solid Edge, we can see that the 1st parameter is the length of the array and the 2nd parameter is the actual array.

 

void AddToGroup(Int32 NumComponents, ref Object[] Components)

There are several ways to create the System.Array parameters. The easiest that I've found is to use a generic List<>.

Imports System.IO
Imports System.Runtime.InteropServices

Module Example
    <STAThread()>
    Sub Main()

        Dim objApplication As SolidEdgeFramework.Application = Nothing
        Dim objAssemblyDocument As SolidEdgeAssembly.AssemblyDocument = Nothing
        Dim objAssemblyCopies As SolidEdgeAssembly.AssemblyCopies = Nothing
        Dim objAssemblyCopy As SolidEdgeAssembly.AssemblyCopy = Nothing
        Dim objAssemblyGroups As SolidEdgeAssembly.AssemblyGroups

        Try
            Examples.OleMessageFilter.Register()

            objApplication = Marshal.GetActiveObject("SolidEdge.Application")
            objAssemblyDocument = objApplication.ActiveDocument
            objAssemblyGroups = objAssemblyDocument.AssemblyGroups

            Dim ComponentsList As New List(Of Object)

            ' Add desired objects to list.
            'ComponentsList.Add(object1)
            'ComponentsList.Add(object2)

            objAssemblyGroups.Add(ComponentsList.Count, ComponentsList.ToArray())

        Catch ex As Exception
            Console.WriteLine(ex.Message)
        Finally
            Examples.OleMessageFilter.Unregister()
        End Try
    End Sub
End Module
Jason Newell
Applications Architect
www.jasonnewell.net

Re: Selected object to Assembly Group

Pioneer
Pioneer

Hi Greg, thank you for fast reply. I understand you, but I still need help with: 

1. defining system array (I tried million manners which didn't works)

2. converting COM object from selection set as they could be assigned to the system array.

 

Lubos

 

Re: Selected object to Assembly Group

Pioneer
Pioneer

Hi Jason, it looks like a solution - I need to try, but many thanks. I'll let you know.

Re: Selected object to Assembly Group

Siemens Phenom Siemens Phenom
Siemens Phenom

You should be able to modify Jason's example with the following to transfer the select set objects to the component list:

 

Dim objSelectSet As SolidEdgeFramework.SelectSet = Nothing

objSelectSet = objApplication.ActiveDocument.SelectSet

If objSelectSet.Count <> 0

    Dim ComponentsList As New List(Of Object)

    For k = 1 To objSelectSet.Count

        ComponentsList.Add(objSelectSet.Item(k))

    Next

    objAssemblyGroups.Add(ComponentsList.Count, ComponentsList.ToArray())

End If

 

 

Greg

Re: Selected object to Assembly Group

Pioneer
Pioneer

Thank you Greg. Now it looks very easy Smiley Happy

 

Lubos

Re: Selected object to Assembly Group

Great Code Snippet!

How can i rename the new generated AssemblyGroup?

 objAssemblyGroup = objAssemblyGroups.Add(ComponentsList.Count, ComponentsList.ToArray())

                objAssemblyGroup.Name = "NewGroupName"

This Code don't rename the new Group!?

 

 

 

Greetings from Switzerland

Re: Selected object to Assembly Group

Siemens Phenom Siemens Phenom
Siemens Phenom

If you look at objAssemblyGroup.Name after you set it to the new name, is it incorrect there or is it just incorrect in the Assembly Pathfinder?

Re: Selected object to Assembly Group

the Name is incorrect in the Assembly Pathfinder