Python Scripting for Inline Components

Python Scripting for Inline Components

ryan.schmitz3D8X3
Participant Participant
2,033 Views
10 Replies
Message 1 of 11

Python Scripting for Inline Components

ryan.schmitz3D8X3
Participant
Participant

Hi, I've had success creating pythons scripts and implementing them in catalogs/specifications for pipe supports, but I'm having difficulty with inline components.  I'm trying to create a strainer with a third port at the basket.  When I test the script using the TESTACPSCRIPT function everything works correctly and the component is created at the origin.  However, when I create a new component using this script and then add it to a specification I get the following error when inserting the component into Plant3D, "Can't find symbol for specified part".  I used the same methodology that I used to create support components and add them to a specification.  Any idea why this wouldn't work in the spec but works in the TESTACPSCRIPT?  I'll add the script below and hope that helps.

 

# Add custom scripts folders to system path
import os
import sys
sys.path.append(os.path.normpath(sys.PnP3dNativeContentCustomScriptsPath))

 

# Import standard libraries
import aqa.math
import math
from varmain.primitiv import *
from varmain.var_basic import *
from varmain.custom import *

 

# Activate support
@Anonymous(Group="Strainer", Ports = "3", TooltipShort="Y-Strainer",TooltipLong="Y-Strainer w/ 3rd Port",LengthUnit="in")

@group("MainDimensions")
@param(ID=LENGTH,TooltipShort="INNER DIA.",TooltipLong="STRAINER INNER DIAMETER")
@param(OD1=LENGTH,TooltipShort="OUTER DIA.",TooltipLong="STRAINER OUTER DIAMETER")
@param(OD2=LENGTH,TooltipShort="FLG. OUTER DIA.",TooltipLong="FLANGE OUTER DIAMETER")
@param(TF=LENGTH,TooltipShort="FLG. THK.",TooltipLong="FLANGE THICKNESS")
@param(L=LENGTH,TooltipShort="LENGTH.",TooltipLong="STRAINER LENGTH")
@param(X=LENGTH,TooltipShort="HOR. LOC.",TooltipLong="HORIZONTAL DISTANCE FROM STRAINER INLET TO BASKET")
@param(Z=LENGTH,TooltipShort="VER. LOC.",TooltipLong="VERTICAL DISTANCE FROM STRAINER INLET TO BASEKET")

def ESY85TEST(s,ID=3.0,OD1=4.5,OD2=9.0,TF=0.875,L=12.13,X=9.0,Z=7.75,**kw):
ob1=CYLINDER(s,R=OD2/2,H=TF,O=ID/2).rotateY(90)
ob2=CYLINDER(s,R=OD1/2,H=L-2*TF,O=ID/2).rotateY(90).translate((TF,0,0))
ob1.uniteWith(ob2)
ob2=CYLINDER(s,R=OD2/2,H=TF,O=ID/2).rotateY(-90).translate((L,0,0))
ob1.uniteWith(ob2)
ob2=CYLINDER(s,R=OD1/2,H=Z*sqrt(2)-0.25,O=ID/2).rotateY(135).translate((X-Z,0,0))
ob3=CYLINDER(s,R=OD1/2,H=L).rotateY(90)
ob2.subtractFrom(ob3)
ob1.uniteWith(ob2)
ob2=CYLINDER(s,R=OD1/2,H=0.25).rotateY(-45).translate((X,0,-Z))
ob1.uniteWith(ob2)
ob2.erase()
ob3.erase()

s.setPoint((0,0,0),(-1,0,0))
s.setPoint((L,0,0),(1,0,0))
s.setPoint((X,0,-Z),(1,0,-1))

return

0 Likes
Accepted solutions (1)
2,034 Views
10 Replies
Replies (10)
Message 2 of 11

h_eger
Mentor
Mentor

Dear @ryan.schmitz3D8X3 ,

 

there seems to be a problem with your script.
I get this error message after "PLANTREGISTERCUSTOMSCRIPTS"

 

Befehl: PLANTREGISTERCUSTOMSCRIPTS

Befehl: Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "varmain\custom.pyc", line 367, in dumpAll
  File "varmain\custom.pyc", line 324, in dumpAll
  File "varmain\custom.pyc", line 306, in dumpFile
  File "d:\autocad plant 3d 2020 content\cpak common\customscripts\ESY85TEST.py", line 30
    ob1=CYLINDER(s,R=OD2/2,H=TF,O=ID/2).rotateY(90)
      ^
IndentationError: expected an indented block

 

 

-

If my reply was helpful, please give a "Kudo" or click the "Accept as Solution" button below (or both).

Hartmut Eger
Senior Engineer
Anlagenplanung + Elektotechnik
XING | LinkedIn

EESignature



0 Likes
Message 3 of 11

rajendra.prajapat
Advisor
Advisor

@ryan.schmitz3D8X3Hi, please remove the indention error on line 30. write your script as per attched image.

Capture.JPG

If my reply was helpful, please give a "Kudo" or click the "Accept as Solution" button below (or both).
0 Likes
Message 4 of 11

ryan.schmitz3D8X3
Participant
Participant

The script must have been copied over correctly.  All lines after "def ESY85TEST(..." are indented by one tab.  That is not what is causing me the issue atm.

0 Likes
Message 5 of 11

h_eger
Mentor
Mentor

may be yes, but at PLANTREGISTERCUSTOMSCIPT I get the error message from line 30 to compile the script.
Now we can discuss for a long time - it still doesn't work!

-

If my reply was helpful, please give a "Kudo" or click the "Accept as Solution" button below (or both).

Hartmut Eger
Senior Engineer
Anlagenplanung + Elektotechnik
XING | LinkedIn

EESignature



0 Likes
Message 6 of 11

ryan.schmitz3D8X3
Participant
Participant

Rajendra,

 

When you indented all lines after def ESY85TEST... did you still have problems compiling?

 

I don't have any problems compiling this script, but the other commenter says it doesn't work for him.  

 

My issue is currently at the catalog/specification level.  This script when used to create a catalog component and then placed in a specification will throw an error when trying to use the component in the specification.  It's odd cause if I run it via the TESTACPSCRIPT command it will work.

 

If you have time, please let me know if the script compiles for you and if you are able to replicate this catalog/specification issue.

 

Thank you for your time Rajendra.

0 Likes
Message 7 of 11

jabowabo
Mentor
Mentor

@ryan.schmitz3D8X3 wrote:

The script must have been copied over correctly.  All lines after "def ESY85TEST(..." are indented by one tab.  That is not what is causing me the issue atm.


Replace the 'tabs' with space(s). The compiler doesn't like tabs.

 

0 Likes
Message 8 of 11

ryan.schmitz3D8X3
Participant
Participant

I replaced the tabs with spaces as suggested.  It still compiles and works with TESTACPSCRIPT.

 

The problem is with the Catalog and Specification.

 

I attached screenshots of the properties and sizes tabs for the created component.

I add this component to a specification then try to insert it into a Plant3D Model and get the following error:

"Geometry can not be generated with the given parameters."

"Can't find symbol for specified part."

 

Any ideas?  Was anyone able to create a catalog component, import it into a specification, then add it to a Plant3D model?

 

 

 

 

0 Likes
Message 9 of 11

rajendra.prajapat
Advisor
Advisor
Accepted solution

@ryan.schmitz3D8X3  please find below updated script. this script working in my pC.

 

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

@activate(Group="Strainer", Ports = "3", TooltipShort="Y-Strainer",TooltipLong="Y-Strainer w/ 3rd Port",LengthUnit="in")
@group("MainDimensions")
@param(ID=LENGTH,TooltipShort="INNER DIA.",TooltipLong="STRAINER INNER DIAMETER")
@param(OD1=LENGTH,TooltipShort="OUTER DIA.",TooltipLong="STRAINER OUTER DIAMETER")
@param(OD2=LENGTH,TooltipShort="FLG. OUTER DIA.",TooltipLong="FLANGE OUTER DIAMETER")
@param(TF=LENGTH,TooltipShort="FLG. THK.",TooltipLong="FLANGE THICKNESS")
@param(L=LENGTH,TooltipShort="LENGTH.",TooltipLong="STRAINER LENGTH")
@param(X=LENGTH,TooltipShort="HOR. LOC.",TooltipLong="HORIZONTAL DISTANCE FROM STRAINER INLET TO BASKET")
@param(Z=LENGTH,TooltipShort="VER. LOC.",TooltipLong="VERTICAL DISTANCE FROM STRAINER INLET TO BASEKET")

def ESY85TEST(s,ID=3.0,OD1=4.5,OD2=9.0,TF=0.875,L=12.13,X=9.0,Z=7.75,**kw):
ob1=CYLINDER(s,R=OD2/2,H=TF).rotateY(90)
ob2=CYLINDER(s,R=OD1/2,H=L-2*TF).rotateY(90).translate((TF,0,0))
ob1.uniteWith(ob2)
ob2=CYLINDER(s,R=OD2/2,H=TF).rotateY(-90).translate((L,0,0))
ob1.uniteWith(ob2)
ob2=CYLINDER(s,R=OD1/2,H=Z*sqrt(2)-0.25).rotateY(135).translate((X-Z,0,0))
ob3=CYLINDER(s,R=OD1/2,H=L).rotateY(90)
ob2.subtractFrom(ob3)
ob1.uniteWith(ob2)
ob2=CYLINDER(s,R=OD1/2,H=0.25).rotateY(-45).translate((X,0,-Z))
ob1.uniteWith(ob2)
ob2.erase()
ob3.erase()

s.setPoint((0,0,0),(-1,0,0))
s.setPoint((L,0,0),(1,0,0))
s.setPoint((X,0,-Z),(1,0,-1))

return

If my reply was helpful, please give a "Kudo" or click the "Accept as Solution" button below (or both).
0 Likes
Message 10 of 11

ryan.schmitz3D8X3
Participant
Participant

Wow that did it!  For some reason it only works in catalogs/specifications when I remove the inner radius for the cylinders.  How you figured that out is beyond me.  Kudos! 

 

This issue has to be an error on AutoCAD's part because I've used hollow cylinders for supports in catalogs/specifications with no problems.  I'd be very interested to know why this is an issue for inline piping components.  

 

Thank you very much Ranjendra, I appreciate you taking the time to help me out. 

Message 11 of 11

mikael.santospj
Enthusiast
Enthusiast

hi guys, how are you all?

Now is my turn to ask. I'm having trouble to make a simple nippled ball valve python script to work properly.

It is a bit frustating, it's been three days of tests, but all aI've got is the block correct.

When I try to create a cusstom part from it, the properties doesn't show me the parameters.

 When I insert the valve into the catalogue and try to create the valve, as a pipeline asset, in plant 3d, the geometry is wrong, the nipples aren't equal, the length isn't correct. And I cant't assignan actuator, it doesn't appear. Then...

1 - Could anyone help me debug the script, is that anything wrong with it?

2 - How to assign the valve actuator to a valvebody created via python script ?

I found this page: https://knowledge.autodesk.com/support/autocad-plant-3d/learn-explore/caas/simplecontent/content/pla.... Still figuring out.

Thanks

0 Likes