Robot Structural Analysis Forum
Welcome to Autodeskā€™s Robot Structural Analysis Forums. Share your knowledge, ask questions, and explore popular Robot Structural Analysis topics.
cancel
Showing results forĀ 
ShowĀ Ā onlyĀ  | Search instead forĀ 
Did you mean:Ā 

(VBA)(API) Code to get Planar loading 3P and contour loaing in Excel

2 REPLIES 2
Reply
Message 1 of 3
muhammad_hasan88NXQ
245 Views, 2 Replies

(VBA)(API) Code to get Planar loading 3P and contour loaing in Excel

Hi Guys,

Wishing every one a happy new year

I am trying to extract panel loading data both Planar loadind 3P and also contour method in Robot 

I am geeting  run-time error 13 Type Mismatch @ hightlighted line if the load type is planar 3P

And No data is extracted if the loading is planar contour 3P

Please help and thanks in advance.

And note I am very new to robot and biginner in VBA.

 

Private Sub CommandButton5_Click()

Dim robapp As New RobotApplication

Dim projPref As RobotProjectPreferences
Set projPref = robapp.Project.Preferences

Dim Fcoeff As Double, Lcoeff As Double
Dim RU As RobotUnitData
Dim RUED As RobotUnitEditionData

Set RU = projPref.Units.Get(I_UT_FORCE)
Set RUED = projPref.Units.UnitEdition.Get(I_UMT_FORCE, projPref.Units.UnitEdition.Find(I_UMT_FORCE, RU.Name))
Fcoeff = RUED.Coefficient
Cells(2, 5) = RU.Name
Cells(2, 6) = Str(RUED.Coefficient)

Set RU = projPref.Units.Get(I_UT_STRUCTURE_DIMENSION)
Set RUED = projPref.Units.UnitEdition.Get(I_UMT_LENGTH, projPref.Units.UnitEdition.Find(I_UMT_LENGTH, RU.Name))
Lcoeff = RUED.Coefficient
Cells(2, 8)= RU.Name
Cells(2, 9) = Str(RUED.Coefficient)


[D9].Value = "Px1 [" + Cells(2, 5) + "/" + Cells(2, 8 )+ "2]"
[E9].Value = "Py1 [" + Cells(2, 5) + "/" + Cells(2, 8 )+ "2]"
[F9].Value = "Pz1 [" + Cells(2, 5) + "/" + Cells(2, 8 )+ "2]"
[G9].Value = "Px2 [" + Cells(2, 5) + "/" + Cells(2, 8 )+ "2]"
[H9].Value = "Py2 [" + Cells(2, 5) + "/" + Cells(2, 8 )+ "2]"
[I9].Value = "Pz2 [" + Cells(2, 5) + "/" + Cells(2, 8 )+ "2]"
[J9].Value = "Px3 [" + Cells(2, 5) + "/" + Cells(2, 8 )+ "2]"
[K9].Value = "Py3 [" + Cells(2, 5) + "/" + Cells(2, 8 )+ "2]"
[L9].Value = "Pz3 [" + Cells(2, 5) + "/" + Cells(2, 8 )+ "2]"
[M9].Value = "X [" + Cells(2, 8 )+ "]"
[N9].Value = "Y [" + Cells(2, 8 )+ "]"
[O9].Value = "Z [" + Cells(2, 8 )+ "]"

Range("A10", "T50000").ClearContents
Dim RCase As IRobotCase
Dim Simplecase As RobotSimpleCase
Dim recs As RobotLoadRecordMngr
Dim rec_1 As RobotLoadRecordInContour
Dim CaseServer As RobotCaseServer
Set CaseServer = robapp.Project.Structure.Cases
Dim row As Integer
Dim xx As Double, yy As Double, zz As Double
row = 10
'check caseServer.Getall.count works
'Cells(1, 1).Value = CaseServer.GetAll.Count
'End Sub
'Sub Tochck()
'works
For i = 1 To CaseServer.GetAll.Count
Set RCase = CaseServer.GetAll.Get(i)
If (RCase.Type = I_CT_SIMPLE) Then
Set Simplecase = RCase
Set recs = Simplecase.Records

For j = 1 To recs.Count
'IF LOADING TYPE : THE PLANAR LOADING 3P ON CONTOUR
If (recs.Get(j).Type = I_LRT_IN_CONTOUR) Then

'always rec_1 is nothing even the loading is planar contour type

Set rec_1 = recs.Get(j)

muhammad_hasan88NXQ_0-1703601355400.png
Cells(row, 1) = RCase.Number
Cells(row, 2) = j
Cells(row, 3) = rec_1.Objects.ToText
Cells(row, 4) = rec_1.GetValue(I_ICRV_PX1) / Fcoeff * Lcoeff * Lcoeff
Cells(row, 5) = rec_1.GetValue(I_ICRV_PY1) / Fcoeff * Lcoeff * Lcoeff
Cells(row, 6) = rec_1.GetValue(I_ICRV_PZ1) / Fcoeff * Lcoeff * Lcoeff
Cells(row, 7) = rec_1.GetValue(I_ICRV_PX2) / Fcoeff * Lcoeff * Lcoeff
Cells(row, 8)= rec_1.GetValue(I_ICRV_PY2) / Fcoeff * Lcoeff * Lcoeff
Cells(row, 9) = rec_1.GetValue(I_ICRV_PZ2) / Fcoeff * Lcoeff * Lcoeff
Cells(row, 10) = rec_1.GetValue(I_ICRV_PX3) / Fcoeff * Lcoeff * Lcoeff
Cells(row, 11) = rec_1.GetValue(I_ICRV_PY3) / Fcoeff * Lcoeff * Lcoeff
Cells(row, 12) = rec_1.GetValue(I_ICRV_PZ3) / Fcoeff * Lcoeff * Lcoeff

For K = 1 To rec_1.GetValue(I_ICRV_NPOINTS)
rec_1.GetContourPoint K, xx, yy, zz
Cells(row, 13) = xx / Lcoeff
Cells(row, 14) = yy / Lcoeff
Cells(row, 15) = zz / Lcoeff
row = row + 1
Next K
'IF LOADING TYPE : THE PLANAR LOADING 3P
ElseIf (recs.Get(j).Type = I_LRT_IN_3_POINTS) Then

'Error 13 Type Mismatch
Set rec_1 = recs.Get(j)
Cells(row, 1) = RCase.Number
Cells(row, 2) = j
Cells(row, 3) = rec_1.Objects.ToText
Cells(row, 4) = rec_1.GetValue(I_3PRV_PX1) / Fcoeff * Lcoeff * Lcoeff
Cells(row, 5) = rec_1.GetValue(I_3PRV_PY1) / Fcoeff * Lcoeff * Lcoeff
Cells(row, 6) = rec_1.GetValue(I_3PRV_PZ1) / Fcoeff * Lcoeff * Lcoeff
Cells(row, 7) = rec_1.GetValue(I_3PRV_PX2) / Fcoeff * Lcoeff * Lcoeff
Cells(row, 8 )= rec_1.GetValue(I_3PRV_PY2) / Fcoeff * Lcoeff * Lcoeff
Cells(row, 9) = rec_1.GetValue(I_3PRV_PZ2) / Fcoeff * Lcoeff * Lcoeff
Cells(row, 10) = rec_1.GetValue(I_3PRV_PX3) / Fcoeff * Lcoeff * Lcoeff
Cells(row, 11) = rec_1.GetValue(I_3PRV_PY3) / Fcoeff * Lcoeff * Lcoeff
Cells(row, 12) = rec_1.GetValue(I_3PRV_PZ3) / Fcoeff * Lcoeff * Lcoeff
For K = 1 To 3
rec_1.GetPoint K, xx, yy, zz
Cells(row, 13) = xx / Lcoeff
Cells(row, 14) = yy / Lcoeff
Cells(row, 15) = zz / Lcoeff
row = row + 1
Next K
End If
Next j
End If

Next i

 

End Sub

Labels (4)
2 REPLIES 2
Message 2 of 3

Hi, 

That happens because that variable should be declared as RobotLoadRecordIn3Points and not RobotLoadRecordInContour. 

Private Sub CommandButton1_Click()
    Dim robapp As New RobotApplication

    Dim projPref As RobotProjectPreferences
    Set projPref = robapp.Project.Preferences

    Dim Fcoeff As Double, Lcoeff As Double
    Dim RU As RobotUnitData
    Dim RUED As RobotUnitEditionData

    Set RU = projPref.Units.Get(I_UT_FORCE)
    Set RUED = projPref.Units.UnitEdition.Get(I_UMT_FORCE, projPref.Units.UnitEdition.Find(I_UMT_FORCE, RU.Name))
    Fcoeff = RUED.Coefficient
    Cells(2, 5) = RU.Name
    Cells(2, 6) = Str(RUED.Coefficient)

    Set RU = projPref.Units.Get(I_UT_STRUCTURE_DIMENSION)
    Set RUED = projPref.Units.UnitEdition.Get(I_UMT_LENGTH, projPref.Units.UnitEdition.Find(I_UMT_LENGTH, RU.Name))
    Lcoeff = RUED.Coefficient
    Cells(2, šŸ˜Ž = RU.Name
    Cells(2, 9) = Str(RUED.Coefficient)


    [D9].Value = "Px1 [" + Cells(2, 5) + "/" + Cells(2, šŸ˜Ž + "2]"
    [E9].Value = "Py1 [" + Cells(2, 5) + "/" + Cells(2, šŸ˜Ž + "2]"
    [F9].Value = "Pz1 [" + Cells(2, 5) + "/" + Cells(2, šŸ˜Ž + "2]"
    [G9].Value = "Px2 [" + Cells(2, 5) + "/" + Cells(2, šŸ˜Ž + "2]"
    [H9].Value = "Py2 [" + Cells(2, 5) + "/" + Cells(2, šŸ˜Ž + "2]"
    [I9].Value = "Pz2 [" + Cells(2, 5) + "/" + Cells(2, šŸ˜Ž + "2]"
    [J9].Value = "Px3 [" + Cells(2, 5) + "/" + Cells(2, šŸ˜Ž + "2]"
    [K9].Value = "Py3 [" + Cells(2, 5) + "/" + Cells(2, šŸ˜Ž + "2]"
    [L9].Value = "Pz3 [" + Cells(2, 5) + "/" + Cells(2, šŸ˜Ž + "2]"
    [M9].Value = "X [" + Cells(2, šŸ˜Ž + "]"
    [N9].Value = "Y [" + Cells(2, šŸ˜Ž + "]"
    [O9].Value = "Z [" + Cells(2, šŸ˜Ž + "]"

    Range("A10", "T50000").ClearContents
    Dim RCase As IRobotCase
    Dim Simplecase As RobotSimpleCase
    Dim recs As RobotLoadRecordMngr
    Dim rec_1 As RobotLoadRecordInContour
    Dim rec_2 As RobotLoadRecordIn3Points
    Dim CaseServer As RobotCaseServer
    Set CaseServer = robapp.Project.Structure.Cases
    Dim row As Integer
    Dim xx As Double, yy As Double, zz As Double
    row = 10
    'check caseServer.Getall.count works
    'Cells(1, 1).Value = CaseServer.GetAll.Count
    'End Sub
    'Sub Tochck()
    'works
    For i = 1 To CaseServer.GetAll.Count
        Set RCase = CaseServer.GetAll.Get(i)
        If (RCase.Type = I_CT_SIMPLE) Then
            Set Simplecase = RCase
            Set recs = Simplecase.Records

            For j = 1 To recs.Count
                'IF LOADING TYPE : THE PLANAR LOADING 3P ON CONTOUR
                If (recs.Get(j).Type = I_LRT_IN_CONTOUR) Then

                    'always rec_1 is nothing even the loading is planar contour type

                    Set rec_1 = recs.Get(j)

                    Cells(row, 1) = RCase.Number
                    Cells(row, 2) = j
                    Cells(row, 3) = rec_1.Objects.ToText
                    Cells(row, 4) = rec_1.GetValue(I_ICRV_PX1) / Fcoeff * Lcoeff * Lcoeff
                    Cells(row, 5) = rec_1.GetValue(I_ICRV_PY1) / Fcoeff * Lcoeff * Lcoeff
                    Cells(row, 6) = rec_1.GetValue(I_ICRV_PZ1) / Fcoeff * Lcoeff * Lcoeff
                    Cells(row, 7) = rec_1.GetValue(I_ICRV_PX2) / Fcoeff * Lcoeff * Lcoeff
                    Cells(row, šŸ˜Ž = rec_1.GetValue(I_ICRV_PY2) / Fcoeff * Lcoeff * Lcoeff
                    Cells(row, 9) = rec_1.GetValue(I_ICRV_PZ2) / Fcoeff * Lcoeff * Lcoeff
                    Cells(row, 10) = rec_1.GetValue(I_ICRV_PX3) / Fcoeff * Lcoeff * Lcoeff
                    Cells(row, 11) = rec_1.GetValue(I_ICRV_PY3) / Fcoeff * Lcoeff * Lcoeff
                    Cells(row, 12) = rec_1.GetValue(I_ICRV_PZ3) / Fcoeff * Lcoeff * Lcoeff

                    For K = 1 To rec_1.GetValue(I_ICRV_NPOINTS)
                        rec_1.GetContourPoint K, xx, yy, zz
                        Cells(row, 13) = xx / Lcoeff
                        Cells(row, 14) = yy / Lcoeff
                        Cells(row, 15) = zz / Lcoeff
                        row = row + 1
                    Next K
                    'IF LOADING TYPE : THE PLANAR LOADING 3P
                ElseIf (recs.Get(j).Type = I_LRT_IN_3_POINTS) Then

                    'Error 13 Type Mismatch
                    Set rec_2 = recs.Get(j)
                    Cells(row, 1) = RCase.Number
                    Cells(row, 2) = j
                    Cells(row, 3) = rec_2.Objects.ToText
                    Cells(row, 4) = rec_2.GetValue(I_3PRV_PX1) / Fcoeff * Lcoeff * Lcoeff
                    Cells(row, 5) = rec_2.GetValue(I_3PRV_PY1) / Fcoeff * Lcoeff * Lcoeff
                    Cells(row, 6) = rec_2.GetValue(I_3PRV_PZ1) / Fcoeff * Lcoeff * Lcoeff
                    Cells(row, 7) = rec_2.GetValue(I_3PRV_PX2) / Fcoeff * Lcoeff * Lcoeff
                    Cells(row, šŸ˜Ž = rec_2.GetValue(I_3PRV_PY2) / Fcoeff * Lcoeff * Lcoeff
                    Cells(row, 9) = rec_2.GetValue(I_3PRV_PZ2) / Fcoeff * Lcoeff * Lcoeff
                    Cells(row, 10) = rec_2.GetValue(I_3PRV_PX3) / Fcoeff * Lcoeff * Lcoeff
                    Cells(row, 11) = rec_2.GetValue(I_3PRV_PY3) / Fcoeff * Lcoeff * Lcoeff
                    Cells(row, 12) = rec_2.GetValue(I_3PRV_PZ3) / Fcoeff * Lcoeff * Lcoeff
                    For K = 1 To 3
                        rec_2.GetPoint K, xx, yy, zz
                        Cells(row, 13) = xx / Lcoeff
                        Cells(row, 14) = yy / Lcoeff
                        Cells(row, 15) = zz / Lcoeff
                        row = row + 1
                    Next K
                End If
            Next j
        End If

    Next i
End Sub

 

kind regards

Message 3 of 3

Hi rsousa, Thank you for your help.

 

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report