How to copy data from Excel to Family members dimensions?

 

Hi!

 

Now I'm writing a macro (into Excel VBA) that retrieves data from Excel and create family of details in active Part. Now

 

the program can create family members by means of FamilyMembers.Add Method. But I am at a loss what command can

 

substitute value of a variable for the family members.  I found in the manual sesdk this phrase:  "To modify the

 

value of a variable of a family member, obtain the family member, then change the value using the member's Value

 

method." But I can’t understand what to do.  Does anybody know anything about it?  I’m not a programmer, but I’m 

 

learning.

This my code, which add Family members:

Private Sub CommandButton1_Click()

    Dim objApp As SolidEdgeFramework.Application

    Dim objDoc As SolidEdgePart.PartDocument

    Dim objFamilys As SolidEdgePart.FamilyMembers

    Dim objFamily As SolidEdgePart.FamilyMember

    Dim cA As String, cB As Double, myRow As Integer

 

    ' Report errors

    Const PI = 3.14159265358979

    ' Create/get the application with specific settings

    On Error Resume Next

    Set objApp = GetObject(, "SolidEdge.Application")

    If Err Then

        Err.Clear

        objApp.Visible = True

    Else

        Set objDoc = objApp.ActiveDocument

    End If

    objApp.DelayCompute = True

 

            myRow = 2

            With ActiveWorkbook.ActiveSheet

                Do While Not IsEmpty(.Cells(myRow, 1))

                cA = CStr(.Cells(myRow, 1))

                cB = CStr(.Cells(myRow, 2))

                Set objFamilys = objDoc.FamilyMembers.Add(cA)

                Set objFamily = objFamilys.Item(1)

                myRow = myRow + 1

                Loop

            End With

        odjApp.DelayCompute = False

    Set objApp = Nothing

    Set objDoc = Nothing

    Set objFamily = Nothing

End Sub

How copy data from Excel to family members dimensions??

Thanks for the help!

 

Posted by: Anton Bykov
Post date: 5/6/2010 1:31:57 AM

13 REPLIES

RE: How to copy data from Excel to Family members dimensions?

 

Maybe following should work (If I understand correctly, cB is the value that you want to put in the variable):

 

objFamilys.Item(1).Variables("VarName").Value = cB

 

Not sure if cB should be a string.

 

- Sanjay Kulkarni[script removed] 

 

Posted by: Sanjay Kulkarni
Post date: 5/6/2010 2:58:23 AM

RE: How to copy data from Excel to Family members dimensions?

 

Sanjay, Thank you for your answer!

 

Realy, in my code cB is the value from Excel cell (for example 10). Active part has 3 variables: A, B and C.

I try to use this code now, but it don't work. (In next code DN - name member; cA, cB, cC - values from Excel, which correspond the value variables A, B, C.)

 

Dim DN As String, cA As String, cB As String, cC As String, myRow As Integer

...

myRow = 2

            With ActiveWorkbook.ActiveSheet

                Do While Not IsEmpty(.Cells(myRow, 1))

                DN = CStr(.Cells(myRow, 1))

                cA = CStr(.Cells(myRow, 2))

                cB = CStr(.Cells(myRow, 3))

                cC = CStr(.Cells(myRow, 4))

                Set objFamilys = objDoc.FamilyMembers.Add(DN)

                objFamilys.Item(1).Variables(A).Value = cA

                objFamilys.Item(1).Variables(B).Value = cB

                objFamilys.Item(1).Variables(C).Value = cC

                myRow = myRow + 1

                Loop

            End With

 

Maybe I was wrong to do something? (sorry for my english)

 

Posted by: Anton Bykov
Post date: 5/6/2010 5:27:43 AM

RE: How to copy data from Excel to Family members dimensions?

 

[script removed]

Frantic,

Try

               objFamilys.Item(1).Variables("A").Value = cA

                objFamilys.Item(1).Variables("B").Value = cB

                objFamilys.Item(1).Variables("C").Value = cC

If it still does not work, post your sample part here and I can explore and try to find the solution. 

[script removed] 

 

Posted by: Sanjay Kulkarni
Post date: 5/6/2010 6:04:18 AM

RE: How to copy data from Excel to Family members dimensions?

 

Sanjay, I tried, but it still doesn't work.

Maybe cA, cB, cC is not As String?

Try it, please. Thank you!

 

Posted by: Anton Bykov
Post date: 5/6/2010 6:23:05 AM

RE: How to copy data from Excel to Family members dimensions?

Frantic,

 

the following statement worked for me:

 

pDoc.FamilyMembers(1).Variable("Ht1").Value = 200

 

where Ht1 represents a sketch dimension.

 

One mistake I made was variables. it should be variable.

 

Also note that 200 is not a string value. Variables can't accept string values.

 

Posted by: Sanjay Kulkarni
Post date: 5/6/2010 7:25:46 AM

RE: How to copy data from Excel to Family members dimensions?

Sanjay,

 

strangely, but it don't work for me.

Are you sure, what Ht1 is dimension, but not variable?

 

Posted by: Anton Bykov
Post date: 5/7/2010 2:53:51 AM

RE: How to copy data from Excel to Family members dimensions?

Frantic,

 

Isn't it possible to use the variables.edit method? There are indeed some issues regarding variables and dimension, see other discussions on this site.

 

pDoc.FamilyMembers(1).Variables.Edit ("Ht1","200") (both name and value should be string data type.)

 

 

 

 

 

 

 

Posted by: Wouter Sloof
Post date: 5/9/2010 10:28:45 PM

RE: How to copy data from Excel to Family members dimensions?

 

ErWo,

variables.edit method don't work. It edit variables of parent part, but not variables of each members of family.

 

Maybe I expressed the problem is unclear. I wont to move data from Excel (Pic1) to table of family of parts (Pic2).

This my code, which add members of family to table of FOP.

Private Sub CommandButton1_Click()

    Dim objApp As SolidEdgeFramework.Application

    Dim objDoc As SolidEdgePart.PartDocument

    Dim objFamilys As SolidEdgePart.FamilyMembers

    Dim DN As String, cA As String, cB As String, cC As String, myRow As Integer

 

    ' Report errors

    Const PI = 3.14159265358979

    ' Create/get the application with specific settings

    On Error Resume Next

    Set objApp = GetObject(, "SolidEdge.Application")

    If Err Then

        Err.Clear

        objApp.Visible = True

    Else

        Set objDoc = objApp.ActiveDocument

    End If

    objApp.DelayCompute = True

 

            myRow = 2

            With ActiveWorkbook.ActiveSheet

                Do While Not IsEmpty(.Cells(myRow, 1))

                DN = CStr(.Cells(myRow, 1))

                cA = CStr(.Cells(myRow, 2))

                cB = CStr(.Cells(myRow, 3))

                cC = CStr(.Cells(myRow, 4))

                Set objFamilys = objDoc.FamilyMembers.Add(DN)

                myRow = myRow + 1

                Loop

            End With

        odjApp.DelayCompute = False

    Set objFamilys = Nothing

    Set objDoc = Nothing

    Set objApp = Nothing

 

End Sub

In SeSdk described this methods and properties, bot I don't know, how it use

NameDescription AddAdds an occurrence of the referenced object. AddFamilyVariableThis method adds a variable to a family of parts. CopyThis method copies a specified FamilyMember object to a new FamilyMember object ItemThis method returns the items in a collection, providing a mechanism for iterating through all or part of the items. RemoveFamilyVariableThis method removes a variable from a FamilyMember object.

Properties

NameDescription ApplicationThe Application object in which the referenced object is active. CountReturns the number of objects in the referenced collection. FamilyVariableReturns a Dimension or Variable object with a specified array for the referenced FamilyMember object. FamilyVariableCountReturns the number of variables defined in the referenced FamilyMember object. ParentReturns the parent object for the referenced object.

AddSuppressedFeatureThis method adds a feature to the list of suppressed features of the referenced FamilyMember object. ApplyApplies the current configuration settings and redisplays the object. DeleteDeletes the referenced object. GetDimensionsThis method returns the dimensions for the referenced object. PopulateCreates a Part document for the referenced FamilyMember object. RemoveSuppressedFeatureThis method removes a feature from the list of suppressed features for the referenced FamilyMember object.

Properties NameDescription ApplicationThe Application object in which the referenced object is active. AttributeSetsReturns the AttributeSets collection object for the referenced object. DescriptionDescription Property DisplayNameThis read-only String property returns the display name for the referenced object. DocumentNameSets and returns the name of the full-path specification of the PartDocument name that contains the referenced DividedPart or FamilyMember object. EdgebarNameThis read-only property returns the Edgebar name of the referenced object. IsAttributeSetPresentReturns True if a specified Attribute Set exists on the referenced object. NameReturns the name of the referenced object. ParentReturns the parent object for the referenced object. StatusReturns the status of the specified object. SuppressedFeatureReturns the suppressed feature having a specified index of a part in a family. SuppressedFeatureCountReturns the number of suppressed features in a family of parts. SystemNameThis read-only String property returns the system name for the referenced object. TypeSpecifies the type of the object being referenced. ValueReturns the name of the application, the value of a dimension, the value of a custom property, or the value of a variable. VariableReturns a Variable object having a specified index for the referenced FamilyMember object. VariableCountReturns the number of variables in a FamilyMember object.

 

Posted by: Anton Bykov
Post date: 5/10/2010 8:16:29 AM

RE: How to copy data from Excel to Family members dimensions?

I'm so happy!! I did it!!!

 

Just:

 

Set objFamilys = objDoc.FamilyMembers

objFamilys.AddFamilyVariable ("A")

objFamilys.AddFamilyVariable ("B")

objFamilys.AddFamilyVariable ("C")

 

and:

 

objFamilys.Add (DN)

objFamilys(DN).Variable("A").Value = cA

 

Thank you all for help to me!

 

Posted by: Anton Bykov
Post date: 5/11/2010 4:54:51 AM