Hi,
I appreciate that this has been answered elsewhere on this forum however these posts haven't helped me. I'm trying to update bar sections (standard UB and UC) in a model with 12,500 bars. I have a table in excel (see table.png below) and want to click the button which runs the following VB code to update the bar sections.
Sub Update_Bars_3() Application.ScreenUpdating = False Dim robapp As RobotApplication Set robapp = New RobotApplication Dim lab_serv As RobotLabelServer Set lab_serv = robapp.Project.Structure.Labels Set myrange = Range(Range("A7"), Range("A7").End(xlDown)) For Each Cell In myange Dim bar As RobotBar Dim Bar_Number As Long Bar_Number = Cell.Value 'Set bar = robapp.Project.Structure.Bars.Get(Bar_Number) Set bar = Structure.Bars.Get(Bar_Number) Dim rr_section As String rr_section = Cell.Offset(0, 3) bar.SetLabel I_LT_BAR_SECTION, rr_section Set bar = Nothing Next Cell Set robapp = Nothing Application.ScreenUpdating = True End Sub
Unfortunately this gives me a "Runtime error 13, type mismatch" error.
Any help with this would be greatly appreciated.
As a follow on question: do I have to have the UB and UC section already added to the Robot sections dialogue box window in order to update the bar table? Is there an easy way to just update the bar table with any (robot valid) standard UB or UC? Or perhaps using the API I can populate the sections list with all the UBs and UCs?
Many thanks, Rob
Solved! Go to Solution.
Solved by Rafal.Gaweda. Go to Solution.
myange <> myrange
For Each Cell In myrange Dim bar As RobotBar Dim Bar_Number As Long Bar_Number = Cell.Value Set bar = robapp.Project.Structure.Bars.Get(Bar_Number) Dim rr_section As String rr_section = Cell.Offset(0, 3) bar.SetLabel I_LT_BAR_SECTION, rr_section Set bar = Nothing Next Cell
As a follow on question: do I have to have the UB and UC section already added to the Robot sections dialogue box window in order to update the bar table? Is there an easy way to just update the bar table with any (robot valid) standard UB or UC? Or perhaps using the API I can populate the sections list with all the UBs and UCs?
Example:
Dim robapp As RobotApplication Set robapp = New RobotApplication Dim lab_serv As RobotLabelServer Set lab_serv = robapp.Project.Structure.Labels Set myrange = Range(Range("A7"), Range("A7").End(xlDown)) Dim SecLab As RobotLabel Dim SecData As RobotBarSectionData robapp.Project.Preferences.SetCurrentDatabase I_DT_SECTIONS, "UKST" For Each Cell In myrange Dim bar As RobotBar Dim Bar_Number As Long Bar_Number = Cell.Value Set bar = robapp.Project.Structure.Bars.Get(Bar_Number) Dim rr_section As String rr_section = Cell.Offset(0, 3) Set SecLab = robapp.Project.Structure.Labels.Create(I_LT_BAR_SECTION, rr_section) Set SecData = SecLab.Data SecData.LoadFromDBase rr_section robapp.Project.Structure.Labels.Store SecLab bar.SetLabel I_LT_BAR_SECTION, rr_section Set bar = Nothing Next Cell