VBA Excel macro for any object geometry modifications (API)

VBA Excel macro for any object geometry modifications (API)

Rafal.Gaweda
Autodesk Support Autodesk Support
28,723 Views
63 Replies
Message 1 of 64

VBA Excel macro for any object geometry modifications (API)

Rafal.Gaweda
Autodesk Support
Autodesk Support

Hi

 

For those who might be interested I am attaching xls file with macro for objects geometry modifications.

One button to import geometry (characteriscic points coordinates) of selected objects (lines, polylines, arc, circles, panels), second - to update their geometry basing on data in Excell.

NOTE: modify only cells with coordinates.



Rafal Gaweda
Accepted solutions (1)
28,724 Views
63 Replies
Replies (63)
Message 41 of 64

Rafal.Gaweda
Autodesk Support
Autodesk Support

Hi @Anonymous

 

What do you mean by "generic"?

This was example for concrete beam section.

 

Cells(2, 10) = RBSCRD.GetValue(I_BSCDV_BEAM_H)


Rafal Gaweda
0 Likes
Message 42 of 64

Anonymous
Not applicable

@Rafal.Gaweda Concrete beam section is generic for me!!!Smiley LOL

But still does not work something...

Dim RLabel As RobotLabel
Dim RBSD As RobotBarSectionData
Dim RBSCRD As RobotBarSectionConcreteData
Dim LabelName As String


Set RBSD = RLabel.Data
Set RBSCRD = RBSD.Concrete
Cells(10, 10) = RBSCRD.GetValue(I_BSCDV_BEAM_B)
Cells(11, 10) = RBSCRD.GetValue(I_BSCDV_BEAM_H)
0 Likes
Message 43 of 64

Rafal.Gaweda
Autodesk Support
Autodesk Support

Hi @Anonymous

 

b30x50.jpg



Rafal Gaweda
0 Likes
Message 44 of 64

Anonymous
Not applicable

why do I get always a beam 30 x 50? Also I do not understand why this row:

Set RLabel = RobApp.Project.Structure.Labels.Get(I_LT_BAR_SECTION, "B 30x50")

the bar section can have whatever dimensions. 

0 Likes
Message 45 of 64

Rafal.Gaweda
Autodesk Support
Autodesk Support

Hi @Anonymous

 

This was JUST EXAMPLE.

Replace "B ...." by labelname \ string.



Rafal Gaweda
0 Likes
Message 46 of 64

Anonymous
Not applicable

@Rafal.Gaweda I have tried but...still problem Man Frustrated

 

Set RLabel = RobApp.Project.Structure.Labels.Get(I_LT_BAR_SECTION, "Labelname")
Set Labelname = String
0 Likes
Message 47 of 64

Rafal.Gaweda
Autodesk Support
Autodesk Support

@Anonymous

 

Dim Labelname as String
Labelname = "B 30x50" ' here you have to give \ input real section name
Set RLabel = RobApp.Project.Structure.Labels.Get(I_LT_BAR_SECTION, Labelname)



Rafal Gaweda
Message 48 of 64

Anonymous
Not applicable

Thanks @Rafal.Gaweda for you patience!

What I do not understand if it is mandatory to write a Labelname (e.g. "B 30x50") or is it possible to skip it. Because like this I need to know, before importing dimensions into excel, the labelname of the section. I cannot import dimensions without know the labelname, nevertheless each time I have to change LabelName in the code. 

 

For example, if you want to get thickness  value for panels, you do not need to know the panel's thickness name. 

the code is:

 Set THData = Obj.GetLabel(I_LT_PANEL_THICKNESS).Data
                If (THData.ThicknessType = I_TT_HOMOGENEOUS) Then
                        Set HomoThickData = THData.Data
                        If (HomoThickData.Type = I_THT_CONSTANT) Then
                        Cells(Row, 2) = HomoThickData.ThickConst 
         

Now, is it a code where I can get bar section dimensions directly as we do for panel?

0 Likes
Message 49 of 64

Rafal.Gaweda
Autodesk Support
Autodesk Support

Hi @Anonymous

 

Sure you can do it in similar way.

Example code :

 

Dim Bar As RobotBar
Dim SectionLabel As RobotLabel
Dim RBSD As RobotBarSectionData
Dim RBSCRD As RobotBarSectionConcreteData

Set Bar = RobApp.Project.Structure.Bars.Get(1)
Set SectionLabel = Bar.GetLabel(I_LT_BAR_SECTION)
Set RBSD = SectionLabel.Data

If (RBSD.ShapeType = I_BSST_CONCR_BEAM_RECT) Then
    Set RBSCRD = RBSD.Concrete
    Cells(1, 1) = RBSCRD.GetValue(I_BSCDV_BEAM_B)
    Cells(2, 1) = RBSCRD.GetValue(I_BSCDV_BEAM_H)
End If


Rafal Gaweda
0 Likes
Message 50 of 64

Anonymous
Not applicable

Thanks @Rafal.Gaweda

But...I get this error

screen1.JPG

 

0 Likes
Message 51 of 64

Rafal.Gaweda
Autodesk Support
Autodesk Support

Hi @Anonymous

 

Do you have bar number 1 in your model?

The example code works for bar with number 1.



Rafal Gaweda
0 Likes
Message 52 of 64

Rafal.Gaweda
Autodesk Support
Autodesk Support

@Anonymous

 

Do you have such line in your code:

Dim Bar As RobotBar

 or

Dim Bar As IRobotBar

 



Rafal Gaweda
0 Likes
Message 53 of 64

Anonymous
Not applicable

@Rafal.Gaweda

Can It works for any bar?

Because If i do not put any bars number between brackets I do not get value

Set Bar = RobApp.Project.Structure.Bars.Get()
0 Likes
Message 54 of 64

Rafal.Gaweda
Autodesk Support
Autodesk Support

Hi @Anonymous

 

If "any" means every RC Beam with rectangular section :

 

Dim Bar As RobotBar
Dim SectionLabel As RobotLabel
Dim RBSD As RobotBarSectionData
Dim RBSCRD As RobotBarSectionConcreteData
Dim BarCollection As RobotBarCollection

Set BarCollection = RobApp.Project.Structure.Bars.GetAll
Row = 1
For I = 1 To BarCollection.Count

Set Bar = BarCollection.Get(I)
Set SectionLabel = Bar.GetLabel(I_LT_BAR_SECTION)
Set RBSD = SectionLabel.Data

If (RBSD.ShapeType = I_BSST_CONCR_BEAM_RECT) Then
    Set RBSCRD = RBSD.Concrete
    Cells(Row, 1) = RBSCRD.GetValue(I_BSCDV_BEAM_B)
    Cells(Row, 2) = RBSCRD.GetValue(I_BSCDV_BEAM_H)
    Row = Row + 1
End If

Next I

 



Rafal Gaweda
Message 55 of 64

Anonymous
Not applicable

Thank so much @Rafal.Gaweda,

if you could do the last effort would be great!

Is it possible to import only bars that are selected in Robot, instead of importing all of them please? 

0 Likes
Message 56 of 64

Rafal.Gaweda
Autodesk Support
Autodesk Support

Hi @Anonymous

 

Have fun:

 

Dim BarSelection As RobotSelection
Dim BarCollection As RobotBarCollection

Set BarSelection = RobApp.Project.Structure.Selections.Get(I_OT_BAR)
Set BarCollection = RobApp.Project.Structure.Bars.GetMany(BarSelection)


Rafal Gaweda
Message 57 of 64

Anonymous
Not applicable

Sorry, I have a problem.

 

When i click in Update objects appears: 

Error.PNG

What I do?

 

Thanks.

0 Likes
Message 58 of 64

Rafal.Gaweda
Autodesk Support
Autodesk Support

Hi @Anonymous

 

My guess is You are running more than 1 Robot at the same time while using this macro .

API macros \ addins work fine only while 1 Robot is running.

 



Rafal Gaweda
0 Likes
Message 59 of 64

Anonymous
Not applicable

Thanks for your answer.

 

I only have one robot running.

The version of robot is 2016, have any problem?

0 Likes
Message 60 of 64

Anonymous
Not applicable

Hi, have you found solution?

0 Likes