Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

How to create Box with Python

#1
Hello, I would like to create boxes from a python script of the dimensions that interest me.
I'm testing but I can't create boxes

Example:
Code:
from robodk import robolink, robomath

RDK = robolink.Robolink()

width = 100  # Ancho de la caja
length = 200  # Largo de la caja
height = 50  # Alto de la caja

# Crear el box
box = RDK.AddObject('Box', robomath.Mat([width, length, height]))

box.setPose(robomath.Mat([0, 0, 0, 0, 0, 0]))  # Matriz de transformación (pose) en (X, Y, Z, Rx, Ry, Rz)

print("Box creado exitosamente en RoboDK.")

Should I use some other function?
#2
Here is an example of how you can create a box.
This script loads a 1*1*1 mm cube from the SLD file and scales it:

Untitled.png   

Code:
from robodk import *
RDK = robolink.Robolink()

box_x_str = mbox("X = ", entry="100.0")
if not box_x_str:
    quit()
else:
    box_x = float(box_x_str)

box_y_str = mbox("Y = ", entry="100.0")
if not box_y_str:
    quit()
else:
    box_y = float(box_y_str)

box_z_str = mbox("Z = ", entry="100.0")
if not box_z_str:
    quit()
else:
    box_z = float(box_z_str)

path = robodialogs.getOpenFileName(path_preference='C:\\', strfile='', strtitle='Open', defaultextension='.*', filetypes=[('Models Files', '.sld')])

box_item = RDK.AddFile(path)
box_item.setName('Box')

box_item.setPose(robomath.transl(0.0, 0.0, 0.0))

box_item.Scale([box_x, box_y, box_z])
box_item.setColor([0.5, 0.5, 0.5])
box_item.setPose(robomath.transl(0.0, 0.0, 0.0))

box_frame_item = RDK.AddFrame('Box Frame')
box_frame_item.setPose(robomath.transl(0.0, 0.0, 0.0))
box_item.setParent(box_frame_item)

You can find the RoboDK Python API description here:
https://robodk.com/doc/en/PythonAPI/index.html

You can also take a look at the Shape Add-in and the Box Spawner Add-in:
https://robodk.com/addin/com.robodk.app.shape
https://robodk.com/addin/com.robodk.app.boxspawner


Attached Files
.sld   cube.sld (Size: 13.27 KB / Downloads: 174)
  




Users browsing this thread:
1 Guest(s)