Creating Panel with Python win32com/API

Creating Panel with Python win32com/API

Anonymous
Not applicable
2,123 Views
12 Replies
Message 1 of 13

Creating Panel with Python win32com/API

Anonymous
Not applicable

After browsing tons of reference codes, I still can't find a way to create panels using API under Python. Could you please provide some pseudo code how to create a panel?

 

Here's what I think it should look like based on what I learned

# Let's say the contour c is predefined

 

panelid= RobApp.Project.Structure.Objects.FreeNumber
panel = RobApp.Project.Structure.Objects.Create(panelid)

panel.Main.Geometry = c

panel.StructuralType = 0  # for panel

panel.AnalyzeTTMethod = True

panel.SetLabel(I_LT_PANEL_THICKNESS, "thickness_name")

panel.SetLabel(I_LT_PANEL_CALC_MODEL, "calcmodel_name")

 

Is the above correct? Am I missing something?

 

Also, a huge blocker is to create new instance of a class. In Excel VBA, I see people simply do 

Dim contour As New RobotGeoContour

How can python do the same thing using win32com? I can't even find IRobotGeoObject class.

 

Thank you for the help! Really appreciated!

0 Likes
Accepted solutions (1)
2,124 Views
12 Replies
Replies (12)
Message 2 of 13

Anonymous
Not applicable
Accepted solution

I figured the solution myself. 

 

To create a new class instance defined in the API using win32com and Python, one has to do the followings:

  1.  Windows Start -> run regedit (Registry Editor)-> HKEY_CLASSES_ROOT : Here shows all the names of COM objects, such as Robot.GeoContour
  2.  In the Python code, the class instance should be declared as:   

contour = win32.DispatchEx("Robot.GeoContour") 

# DispatchEx ensures having duplicate COM object instances if you want to create multiple class instances

 

 

 

0 Likes
Message 3 of 13

Anonymous
Not applicable

Hi,

I am also using Win32com and python interface. But i have problem with creating the contour c . 

 

This was my code . But after i run it i dont see a object in my software. 

Am i creating a geo contour wrong ? or  (obj.Main.Geometry = c) is it right ?? 

 

c= RobotAPILib.IRobotGeoContour
Segment = RobotAPILib.RobotGeoSegmentLine()

Segment.P1.Set(0,0,0)
c.Add(Segment)
Segment.P1.Set(10,0,0)
c.Add(Segment)
Segment.P1.Set(10,10,0)
c.Add(Segment)
Segment.P1.Set(0,10,0)
c.Add(Segment)

c.Initialize
obj.Main.Geometry = c
obj.Main.Attribs.Meshed = True
# obj.SetLabel(robconst.I_LT_PANEL_THICKNESS, SlabSectionName)
obj.Initialize

 

if you dont mind can you share me the code for your contour c. it will help me a lot

0 Likes
Message 4 of 13

kai-hung.changHSCJ3
Contributor
Contributor
def create_panel(segments_in_meter, if_edge_x_is_longer):
# windows Start -> regedit -> HKEY_CLASSES_ROOT (All the names of COM objects)
# Have to use DispatchEx to
contour = win32.DispatchEx("Robot.GeoContour")
for s in segments_in_meter:
gsl = win32.DispatchEx("Robot.GeoSegmentLine")
gsl.P1.Set(*s)
contour.Add(gsl)
del gsl
contour.Initialize()
panelid = project.Structure.Objects.FreeNumber
panel = project.Structure.Objects.Create(panelid)
panel.Main.Geometry = contour
panel.Main.Attribs.Meshed = True
if if_edge_x_is_longer:
panel.Main.Attribs.SetDirX(1, 0, 1, 0)
else:
panel.Main.Attribs.SetDirX(1, 1, 0, 0)
panel.StructuralType = 0
panel.SetLabel(I_LT_PANEL_THICKNESS, "ConXTech")
panel.SetLabel(I_LT_PANEL_CALC_MODEL, "ConXTech")
panel.Initialize()
panel.Update()
del contour
Message 5 of 13

Anonymous
Not applicable

I created my contour similar to your code. just that you used for loop i wrote line by line. 

Can you verify what is my mistake. 

I am not able to see the contour in the software after i run the app. 

0 Likes
Message 6 of 13

kai-hung.changHSCJ3
Contributor
Contributor

Any error message coming out?

0 Likes
Message 7 of 13

kai-hung.changHSCJ3
Contributor
Contributor

You need obj.Update in the end

0 Likes
Message 8 of 13

Anonymous
Not applicable

This is my code .. I dont see any error message 

and i dont see contour or slab in application.  Can you help please 

 

import win32com.client
import RobotAPI_Py_lib as RobotAPILib


# instantiates RobotApplication
robapp = win32com.client.Dispatch("Robot.Application")
# constant type library created when Dispatch is run
robconst = win32com.client.constants


# Visualisation and Control
robapp.Visible = True
robapp.Interactive = True
robapp.Window.Activate
robapp.Project.ViewMngr.Refresh

# creates instance of project (only one allowed)
robapp.Project.New(robconst.I_PT_FRAME_3D)
S = RobotAPILib.RobotStructure
S = robapp.Project.Structure


#Label Creation for cross sections
labels = RobotAPILib.RobotLabelServer
labels = robapp.Project.Structure.Labels

# Naming the Slab and Assigning properties of Slab
SlabSectionName = "Slab"
Slab_Label = labels.Create(robconst.I_LT_PANEL_THICKNESS, SlabSectionName)
thickness = RobotAPILib.RobotThicknessData
thickness = Slab_Label.Data
thickness.MaterialName = "MAT1111"
thickness.ThicknessType = robconst.I_TT_HOMOGENEOUS # For Isotropic
thicknessData = RobotAPILib.RobotThicknessHomoData
thicknessData = thickness.Data
thicknessData.ThickConst = 1
labels.Store(Slab_Label)

# Creating the Slab Object
obj_server = RobotAPILib.RobotObjObjectServer()
obj_server = S.Objects
objNumber = obj_server.FreeNumber

obj = RobotAPILib.RobotObjObject()
obj = obj_server.Create(1)

c= RobotAPILib.RobotGeoContour()
Segment = RobotAPILib.RobotGeoSegmentLine()

Segment.P1.Set(0,0,0)
c.Add(Segment)
Segment.P1.Set(10,0,0)
c.Add(Segment)
Segment.P1.Set(10,10,0)
c.Add(Segment)
Segment.P1.Set(0,10,0)
c.Add(Segment)

c.Initialize()
obj.Main.Geometry = c
obj.Main.Attribs.Meshed = True
obj.SetLabel(robconst.I_LT_PANEL_THICKNESS, SlabSectionName)
obj.Initialize()
obj.Update()

0 Likes
Message 9 of 13

Anonymous
Not applicable

 I think there is a mistake with the way i add segments but i couldnt figureout what it is 

0 Likes
Message 10 of 13

kai-hung.changHSCJ3
Contributor
Contributor

What looks suspicious to me are these:

obj_server = RobotAPILib.RobotObjObjectServer()
obj_server = S.Objects
objNumber = obj_server.FreeNumber

obj = RobotAPILib.RobotObjObject()
obj = obj_server.Create(1)

 

Or another possible bug is here:

Segment = RobotAPILib.RobotGeoSegmentLine()

Segment.P1.Set(0,0,0)
c.Add(Segment)
Segment.P1.Set(10,0,0)
c.Add(Segment)
Segment.P1.Set(10,10,0)
c.Add(Segment)
Segment.P1.Set(0,10,0)
c.Add(Segment)

 

In my code, I create a new GeoSegmentLine in each for loop. Maybe you can try the same thing.

 

0 Likes
Message 11 of 13

Anonymous
Not applicable
The initializations are slightly different between you and me.

Instead of writing project.structure.objects every time i created a variables .
where
S = project.structure

obj_server = project.structure.objects
0 Likes
Message 12 of 13

Anonymous
Not applicable

The code worked when i deleted segment every time before i add a contour segment. 

 

Thanks for the assist 

0 Likes
Message 13 of 13

alexander.silvaGA9XG
Participant
Participant

How to install RobotAPI_Py_lib?

 

0 Likes