Creating a custom flange in Plant 2024

Creating a custom flange in Plant 2024

ines_portilla
Explorer Explorer
329 Views
2 Replies
Message 1 of 3

Creating a custom flange in Plant 2024

ines_portilla
Explorer
Explorer

I'm trying to create a flange using a custom script. Unlike default flanges in Plant 3D, this flange must include an inner hole and some bolt holes. The number of bolt holes must depend on the diameter of the pipe the flange must be connected to. In order to do this, I started developping a script using conditionals. For example, if the flange's inner circle (d) is equal to 16, it must have 4 bolt holes and they must be set 90 degrees apart from each other, but if d = 75, there must be 8 bolt holes 45 degrees apart. So far, Plant 3D is registering my script correctly and is generating a geometry, but for some reason it seems like it's ignoring the conditionals if and elif. I'm testing a flange whose d=110 and is supposed to have 8 bolt holes, but still returns 4. I developped the following script:

 

from varmain.var_basic import *
from aqa.math import *
from varmain.primitiv import *
from varmain.custom import *

@activate(Group="Flange", 
          TooltipShort="Flange", 
          TooltipLong="Standard Flange", 
          FirstPortEndtypes="FL", 
          LengthUnit="mm", 
          Ports="2")
@group("MainDimensions")
@param(D=LENGTH, TooltipShort="Outer Diameter of the Flange")
@param(d=LENGTH, TooltipShort="Pipe Diameter")
@param(KB=LENGTH, TooltipShort="Diameter of bolt circle")
@param(L=LENGTH, TooltipShort="Bolt Hole Diameter")
@param(C=LENGTH, TooltipShort="Flange Thickness")
@param(OF=LENGTH, TooltipShort="Weld offset")
@group(Name="meaningless eum")
@param(K=ENUM)
@enum(1, "align X")
@enum(2, "align Y")
@enum(3, "align Z")

def Bolt_Flange(s, D=210, d=110, KB=162, L=20, C=10, OF=-1, K=1, **kw ):
    F=CYLINDER(s, R=D/2, H=C, O=d/2).rotateY(90)
    
    if d == 16 or d == 20 or d == 25 or d == 32 or d == 40 or d == 50 or d == 63:
        M1 = CYLINDER(s, R=L/2, H=C+2, O=0).rotateY(90).translate((0,0,KB/2))
        M2 = CYLINDER(s, R=L/2, H=C+2, O=0).rotateY(90).translate((0,0,KB/2)).rotateX(90)
        M3 = CYLINDER(s, R=L/2, H=C+2, O=0).rotateY(90).translate((0,0,KB/2)).rotateX(180)
        M4 = CYLINDER(s, R=L/2, H=C+2, O=0).rotateY(90).translate((0,0,KB/2)).rotateX(270)
        
        F.subtractFrom(M1)
        M1.erase()
        F.subtractFrom(M2)
        M2.erase()
        F.subtractFrom(M3)
        M3.erase()
        F.subtractFrom(M4)  
        M4.erase()
    
    elif d == 75 or d == 90 or d == 110 or d == 140 or d == 160:
        M1 = CYLINDER(s, R=L/2, H=C+2, O=0).rotateY(90).translate((0,0,KB/2))
        M2 = CYLINDER(s, R=L/2, H=C+2, O=0).rotateY(90).translate((0,0,KB/2)).rotateX(45)
        M3 = CYLINDER(s, R=L/2, H=C+2, O=0).rotateY(90).translate((0,0,KB/2)).rotateX(90)
        M4 = CYLINDER(s, R=L/2, H=C+2, O=0).rotateY(90).translate((0,0,KB/2)).rotateX(135)
        M5 = CYLINDER(s, R=L/2, H=C+2, O=0).rotateY(90).translate((0,0,KB/2)).rotateX(180)
        M6 = CYLINDER(s, R=L/2, H=C+2, O=0).rotateY(90).translate((0,0,KB/2)).rotateX(225)
        M7 = CYLINDER(s, R=L/2, H=C+2, O=0).rotateY(90).translate((0,0,KB/2)).rotateX(270)
        M8 = CYLINDER(s, R=L/2, H=C+2, O=0).rotateY(90).translate((0,0,KB/2)).rotateX(315)
        
        F.subtractFrom(M1)
        M1.erase()
        F.subtractFrom(M2)
        M2.erase()
        F.subtractFrom(M3)
        M3.erase()
        F.subtractFrom(M4)
        M4.erase()
        F.subtractFrom(M5)
        M5.erase()
        F.subtractFrom(M6)
        M6.erase()
        F.subtractFrom(M7)
        M7.erase()
        F.subtractFrom(M8)
        M8.erase()
        
    elif d == 225 or d == 280:
        M1 = CYLINDER(s, R=L/2, H=C+2, O=0).rotateY(90).translate((0,0,KB/2))
        M2 = CYLINDER(s, R=L/2, H=C+2, O=0).rotateY(90).translate((0,0,KB/2)).rotateX(30)
        M3 = CYLINDER(s, R=L/2, H=C+2, O=0).rotateY(90).translate((0,0,KB/2)).rotateX(60)
        M4 = CYLINDER(s, R=L/2, H=C+2, O=0).rotateY(90).translate((0,0,KB/2)).rotateX(90)
        M5 = CYLINDER(s, R=L/2, H=C+2, O=0).rotateY(90).translate((0,0,KB/2)).rotateX(120)
        M6 = CYLINDER(s, R=L/2, H=C+2, O=0).rotateY(90).translate((0,0,KB/2)).rotateX(150)
        M7 = CYLINDER(s, R=L/2, H=C+2, O=0).rotateY(90).translate((0,0,KB/2)).rotateX(180)
        M8 = CYLINDER(s, R=L/2, H=C+2, O=0).rotateY(90).translate((0,0,KB/2)).rotateX(210)
        M9 = CYLINDER(s, R=L/2, H=C+2, O=0).rotateY(90).translate((0,0,KB/2)).rotateX(240)
        M10 = CYLINDER(s, R=L/2, H=C+2, O=0).rotateY(90).translate((0,0,KB/2)).rotateX(270)
        M11 = CYLINDER(s, R=L/2, H=C+2, O=0).rotateY(90).translate((0,0,KB/2)).rotateX(300)
        M12 = CYLINDER(s, R=L/2, H=C+2, O=0).rotateY(90).translate((0,0,KB/2)).rotateX(330)
        
        F.subtractFrom(M1)
        M1.erase()
        F.subtractFrom(M2)
        M2.erase()
        F.subtractFrom(M3)
        M3.erase()
        F.subtractFrom(M4)
        M4.erase()
        F.subtractFrom(M5)
        M5.erase()
        F.subtractFrom(M6)
        M6.erase()
        F.subtractFrom(M7)
        M7.erase()
        F.subtractFrom(M8)
        M8.erase()
        F.subtractFrom(M9)
        M9.erase()
        F.subtractFrom(M10)
        M10.erase()
        F.subtractFrom(M11)
        M11.erase()
        F.subtractFrom(M12)
        M12.erase()

 

From what I've seen in blogs and tutorials, if, elif and else conditionals are supposed to work in custom scripts, but is it actually possible? And if it is, what should I do to make it work?

 

Thank you in advance

0 Likes
330 Views
2 Replies
Replies (2)
Message 2 of 3

075bme0092MKE4
Explorer
Explorer

can you provide me some info to begin with python in plant 3D ,sorry im not providing you solution but im trying to learn .

 

0 Likes
Message 3 of 3

EddyWagner
Advocate
Advocate

Why don't you try it like this:

if d <= 63.0:
    4 bolts
elif d <= 160.0:
    8 bolts
else:
    12 bolts

Add ".0" to the values.
Example function:

def Bolt_Flange(s, D=210.0, d=110.0, KB=162.0, L=20.0, C=10.0, OF=-1, K=1, **kw):