What's new

Confusion using AddRectangle

idslk

Alibre Super User
I am struggleling with the AddRectangle function (seems to be the same with AddCircle...)
If i use the same values for x and y for the three basic plane i do not know from where the are measured (i assume from the origin) and in wich direction they count.
The script creates 3 cuboid and 3 cylinder. Each cylinder is only to show the position of the lower left corner for the AddRectangle call.

Rectangle.JPG

Code:
# Rectangle-Test
# ...

Win = Windows()

ScriptName = 'Rectangle-Test'

#If Existing Part should be modified
CP = CurrentPart()
CPText= CP.Name

#Extrudelength
EL = 5

#Rectangle Data
P1_X = 5
P1_Y = 10

P2_X = 15
P2_Y = 30

#Circle Data for Cylinder on bottom-left of rectangle
P3_X = P1_X-1
P3_Y = P1_Y-1
DIA = 1

#Use FS1 = 'XY-Plane' at english install of AD
FS1 = 'XY-Ebene'
RE1 = CP.AddSketch('SketchXY', CP.GetPlane(FS1))
RE1.AddRectangle(P1_X, P1_Y, P2_X, P2_Y, False)
RE1.AddCircle(P3_X, P3_Y, DIA, False)
 
# extrude into a cuboid and cylinder
CP.AddExtrudeBoss('Quader1', RE1, EL, False)

FS2 = 'ZX-Ebene'
RE2 = CP.AddSketch('SketchZX', CP.GetPlane(FS2))
RE2.AddRectangle(P1_X, P1_Y, P2_X, P2_Y, False)
RE2.AddCircle(P3_X, P3_Y, DIA, False)
 
# extrude into a cuboid and cylinder
CP.AddExtrudeBoss('Quader2', RE2, EL, False)

FS3 = 'YZ-Ebene'
RE3 = CP.AddSketch('SketchYZ', CP.GetPlane(FS3))
RE3.AddRectangle(P1_X, P1_Y, P2_X, P2_Y, False)
RE3.AddCircle(P3_X, P3_Y, DIA, False)
 
# extrude into a cuboid and cylinder
CP.AddExtrudeBoss('Quader3', RE3, EL, False)

The behaviar of the z-axis (zx-plane) is not like i expected. The extrusion seems to work ok but the position coordinates seem to be multiplied with -1.
Am i doing something wrong?
Does anyone have an explanation for me?

Thanks in advance
Stefan
 

albie0803

Alibre Super User
Yes all measurements are from the origin point. On the XY plane, X is positive to the right of origin and Y is positive above the origin. In all cases, when you activate a sketch, the horizontal axis is positive to the right and the vertical one is positive in the up direction. There is actually no correlation to the axes that run through the plane/sketch. Check in the right of the status bar at the bottom, you can see the co-ordinates of the the mouse pointer on the sketch/plane.
 

idslk

Alibre Super User
Hello albie,

thanks for your reply. I've seen that behaviar during a manual usage of the program.
If i use the script function i'm some kind of "blind" ...
Here some very rough code:
Code:
# Cut Keyway
# ...

Win = Windows()

ScriptName = 'Passfedernut'

#If NewPart is required
#CP = Part('Cylinder')

#If Existing Part should be modified
CP = CurrentPart()
CPText= CP.Name

#Cylinderlength
CL = 50

FS = 'XY-Ebene'
ZYL = CP.AddSketch('CylinderSketch', CP.GetPlane(FS))
ZYL.AddCircle(0, 0, CL, False)
# extrude into a cylinder
CP.AddExtrudeBoss('Cylinder', ZYL, 50, False)

#UserInputWindow
Options = []
#Options.append([None, WindowsInputTypes.Image, 'IDSLK_Logo_test.png', 114])
Options.append(['Choose Circle', WindowsInputTypes.Edge, None])
Options.append(['Choose parallel Baseplane', WindowsInputTypes.Plane, None])
#Options.append(['Startseite des Zylinders waehlen', WindowsInputTypes.Face, None])
Options.append(['Offset', WindowsInputTypes.Real, 5.000])
Values = Win.OptionsDialog(ScriptName, Options, 170)
if Values == None:
  sys.exit()

#Data from choosen part

#Edge
E = Values[0]
EText = E.Name

ED = E.Diameter
EDTextValue = '%f' % (ED)

#Plane
PL = Values[1]
PLText = PL.Name

#StartFace
#F = Values[2]
#FText = F.Name

#TPL = CP.GetPlane('XY-Ebene')
#Test = F.DistanceTo(TPL)
#TestT = '%f' %(Test)
#Win.InfoDialog(TestT,'Test')

#Keyway offset
OS = Values[2]
OSTextValue = '%f' % (OS)

#Keyway Data
KWWidth = 5.000
KWDepth = 3.000
KWLength = 35.000

P1_Y = OS-CL
P1_X = -KWWidth/2

P2_Y = KWLength - CL
P2_X = KWWidth/2

#Create new plane

KWP = CP.AddPlane('KeywayPlane',PL,ED/2)
KWPText = KWP.Name

#Create Keywayrectangle
KWS = CP.AddSketch('KeyWayShape', CP.GetPlane(KWPText))
KWS.AddRectangle(P1_X, P1_Y, P2_X, P2_Y, False)
# cut the part using the rectangle
CP.AddExtrudeCut('Cut', KWS, KWDepth, True)
Try first time with choosing the "zx-plane" then clear up an second time try it with "yz-plane"
How should i handle this without knowing the used plane of the user?
Any ideas?

Thanks in advance
Stefan
 

idslk

Alibre Super User
Hello oldfox,

thank you for your reply. You are right on one hand but i am very lasy on the other hand... I want to do minimum user input and therefor the script has to evaluate which plane is choosen, or better which orientation the choosen plane has, to setup the correct positions for the sketch figure automatically. Of course i can manually do an edit, but i don't want to ;-)

Any suggestions wellcome
Stefan
 

oldfox

Alibre Super User
I'm not sure that AD Ver. 2018.1.1 will do that. Maybe with Ver. 2018.2 There are going to be a lot of AliberScript changes and additions. It may
be just what you are looking for. Stay tuned for release of the 2018.2
 

ajayre

Alibre Super User
I'm not quite sure what you are trying to do, but if you allow the user to choose a design plane and you want to know which one it is, then look at the Name property of the plane and compare it to the built-in names.

Andy
 

idslk

Alibre Super User
Hello Andy,

My wish is to build a sketch figure on the user choosen plane with defined measures.
If i use the same measures for different 2D-planes (x and y coordinates) i get different orientations of the sketch figure.
I've thought about name comparision as well and it will work as long as it is a built-in plane.
If the planes are build by the user - no same name no luck? :)
Is there a way to compare more properties of the choosen plane to the properties of the build-in plane or axis-system?
Or may it be possible to project 3D-points to a 2D-sketch for use in Sketch figures? A lot of questions...but all only for "fun" like: is there a way to measure the distance between face and plane? I'll keep on trying.

Thank you Andy
 

ajayre

Alibre Super User
I'm not sure the importance of the orientation. What happens if a user inserts a custom reference plane at some arbitrary angle and uses that?

You can map 3D to 2D coordinates and vice versa using Sketch.GlobaltoPoint() and Sketch.PointtoGlobal().

Andy
 

idslk

Alibre Super User
- Orientation:
"Keyway spript" with ZX-Plane choosen:
ZX_Plane.JPG
"Keyway spript" with YZ-Plane choosen:
YZ_Plane.JPG
-Plane under an angle:
Haven't tried that yet - maybe tomorrow

Will try the 3D-Point for an other script

Thank you.

Regards
Stefan
 

ajayre

Alibre Super User
I would say the user has to choose a plane that makes sense. Or your script creates the plane for they keyway creation.
 

albie0803

Alibre Super User
It seems with scripting that all measurements are absolute from the origin point. At the moment you can't reference a distance from a plane or axis.
You could ask the user which plane they used and which axis they revolved around eg
if xy-plane and x axis then measurements are "this"
if xy-plane and y axis then measurements are "this" rotated 90°
and so on for each of the six possibilities
but in all cases you are still forced to reference measurements from the origin.

In the case of keyways it would be easier to simply understand that for the script to work correctly and simply that particular planes and axes need to be used.

Build scripts to suit your method of designing and add instructions as to how other users can modify the script to suit them.
 

idslk

Alibre Super User
Hello collegues,
not completed, but something to play with...
Code:
# Cut Keyway
Win = Windows()
ScriptName = 'IDSLK'
#If NewPart is required
#CP = Part('Cylinder')
#If Existing Part should be modified
CP = CurrentPart()
CPText= CP.Name
#Get Base for cylinder
Options = []
#Options.append([None, WindowsInputTypes.Image, 'IDSLK_Logo_test.png', 114])
Options.append(['Choose Baseplane for Cylinder', WindowsInputTypes.Plane, None])
Values = Win.OptionsDialog(ScriptName, Options, 170)
if Values == None:
  sys.exit()
#Create Sketch
FS = Values[0]
ZYL = CP.AddSketch('CylinderSketch', FS)
#CylinderDiameter
CD = 50
ZYL.AddCircle(0, 0, CD, False)
# extrude into a cylinder
#Cylinderlength
CL = 50
CP.AddExtrudeBoss('Cylinder', ZYL, CL, False)

#Main Script
#UserInputWindow
Options = []
#Options.append([None, WindowsInputTypes.Image, 'IDSLK_Logo_test.png', 114])
Options.append(['Choose Axis', WindowsInputTypes.Axis, None])
Options.append(['Choose Circle', WindowsInputTypes.Edge, None])
Options.append(['Choose Keyway Baseplane', WindowsInputTypes.Plane, None])
#Options.append(['Startseite des Zylinders waehlen', WindowsInputTypes.Face, None])
Options.append(['Angle 0..360°', WindowsInputTypes.Real, 15.000])
Options.append(['Offset', WindowsInputTypes.Real, 5.000])
Values = Win.OptionsDialog(ScriptName, Options, 170)
if Values == None:
  sys.exit()

#Data from choosen part
#Axis
A = Values[0]
AText = A.Name
#Edge
E = Values[1]
EText = E.Name
ED = E.Diameter
#EDTextValue = '%f' % (ED)
#Plane
PL = Values[2]
PLText = PL.Name

#StartFace
#F = Values[3]
#FText = F.Name

#PlaneAngle
PA = Values[3]
while PA >= 360: PA = PA-360
PAText = '%f' % (PA)
#KeywayOffset
KO = Values[4]
KOText = '%f' % (KO)
#Keyway Data
KWWidth = 5.000
KWDepth = 3.000
KWLength = 35.000
#Check which Planes are used and adjust x and y coordinates
if 'ZX' in PLText and 'X' in AText and PA<180: P1_X = (CL-KO)*1 ;P1_Y = ED/2 ;P2_X = (CL-KWLength)*1 ;P2_Y = ED/2-KWDepth; print '1'
elif 'ZX' in PLText and 'X' in AText and PA>180: P1_X = (CL-KO)*-1 ;P1_Y = ED/2 ;P2_X = (CL-KWLength)*-1 ;P2_Y = ED/2-KWDepth; print '2'
elif 'ZX' in PLText and 'Z' in AText and PA<180: P1_X = (CL-KO)*1 ;P1_Y = ED/2 ;P2_X = (CL-KWLength)*1 ;P2_Y = ED/2-KWDepth; print '3'
elif 'ZX' in PLText and 'Z' in AText and PA>180: P1_X = (CL-KO)*-1 ;P1_Y = ED/2 ;P2_X = (CL-KWLength)*-1 ;P2_Y = ED/2-KWDepth; print '4'
elif 'YZ' in PLText and 'Z' in AText and PA<90: P1_X = (CL-KO)*-1 ;P1_Y = ED/2 ;P2_X = (CL-KWLength)*-1 ;P2_Y = ED/2-KWDepth; print '5'
elif 'YZ' in PLText and 'Z' in AText and 90<PA<270: P1_X = (CL-KO)*1 ;P1_Y = ED/2 ;P2_X = (CL-KWLength)*1 ;P2_Y = ED/2-KWDepth; print '6'
elif 'YZ' in PLText and 'Z' in AText and PA>270: P1_X = (CL-KO)*-1 ;P1_Y = ED/2 ;P2_X = (CL-KWLength)*-1 ;P2_Y = ED/2-KWDepth; print '7'
elif 'XY' in PLText and 'X' in AText and PA<90: P1_X = (CL-KO)*1 ;P1_Y = ED/2 ;P2_X = (CL-KWLength)*1 ;P2_Y = ED/2-KWDepth; print '8'
elif 'XY' in PLText and 'X' in AText and 90<PA<270: P1_X = (CL-KO)*-1 ;P1_Y = ED/2 ;P2_X = (CL-KWLength)*-1 ;P2_Y = ED/2-KWDepth; print '9'
elif 'XY' in PLText and 'X' in AText and PA>270: P1_X = (CL-KO)*1 ;P1_Y = ED/2 ;P2_X = (CL-KWLength)*1 ;P2_Y = ED/2-KWDepth; print '10'
else: P1_X = ED/2 ; P1_Y = (CL-KO)*1 ; P2_X = ED/2-KWDepth ; P2_Y = (CL-KWLength)*1; print '11'
#Create new plane
KWP = CP.AddPlane('Keyway-Plane',PL,A,PA)
KWS = CP.AddSketch('Keyway-Sketch', KWP)
KWS.AddRectangle(P1_X, P1_Y, P2_X, P2_Y, False)
# cut the part using the rectangle
CP.AddExtrudeCut('Cut', KWS, KWWidth, False, Part.EndCondition.MidPlane, None, 0, Part.DirectionType.Normal, None, 0, False)

any comments are welcome

Thanks
Stefan
 
Top