Custom Pipe Support Python Script Wierdness

Custom Pipe Support Python Script Wierdness

Anonymous
Not applicable
5,267 Views
23 Replies
Message 1 of 24

Custom Pipe Support Python Script Wierdness

Anonymous
Not applicable

I created a custom python script for a variable pipe shoe. Which works well, except for the fact that the shoe is being placed perpendicular to the pipe. And I can't change its orientation.........because when I attempt to rotate the shoe the Z Axis is actually called from the connecting pipe.

 

This is the script:

 

import aqa.math
import math
from varmain.primitiv import *
from varmain.var_basic import *
from varmain.custom import *
 
@Anonymous(Group="Support", TooltipShort="APA SH01 Pipe Shoe Variable", TooltipLong="APA SH01 Pipe Shoe Variable", LengthUnit="mm",Ports="1")
@matthias_hein("MainDimensions")
@param(L1=LENGTH, TooltipShort="Shoe Pad Length", TooltipLong="Shoe Pad Length", Ask4Dist=True)
@param(A1=LENGTH, TooltipShort="Shoe Pad Width", TooltipLong="Shoe Pad Width")
@param(T1=LENGTH, TooltipShort="Shoe Pad Thickness", TooltipLong="Shoe Pad Thickness")
@param(L2=LENGTH, TooltipShort="Shoe Web Length", TooltipLong="Shoe Web Length")
@param(H1=LENGTH, TooltipShort="Shoe Web Thickness", TooltipLong="Shoe Web Thickness")
@param(B=LENGTH, TooltipShort="Shoe Web Height", TooltipLong="Shoe Web Height")
@param(P1=LENGTH, TooltipShort="Main Piperun Diameter", TooltipLong="Main Piperun Diameter")
@matthias_hein(Name="meaningless enum")
@enum(1, "align X")
@enum(2, "align Y")
@enum(3, "align Z")
#--------------------------------------------------------
#(arxload "PnP3dACPAdapter")
#(TESTACPSCRIPT "APASH01" "L1" "300" "A1" "140" "T1" "10" "L2" "300" "H1" "10" "B" "100" "P1" "114")
def APASH01(s, L1 = 300.0, A1 = 140.0, T1 = 10.0, L2 = 300.00, H1 = 10.0, B = 100.0, P1 = 114.3, ID = 'APASH01', **kw):
# create the shoe flange
#   o1 = BOX(s, L=L1, W=A1, H=T1).rotateY(90).translate((0.0, 0.0, - T1 / 2.0))
    BOX(s, L=L1, W=A1, H=T1).rotateY(90).rotateZ(90).translate((0.0, 0.0, - T1 / 2.0))
#--------------------------------------------------------
# create the shoe web
#    o2 = BOX(s, L=L2, W=B, H=H1)
    shoeheight = B - H1
    inspoint = shoeheight + (P1/2)
    BOX(s, L=L2, W=shoeheight, H=H1).rotateY(0).rotateZ(90).translate((0.0, 0.0, shoeheight / 2.0))
#    o1.unitWith(o2)
#    o2.erase()
    s.setPoint((0.0, 0.0, inspoint), (-1.0, 0.0, 0.0))

 

 

And here is what happens. Shoe in the red box has been placed from the Pipe Support Palette (Script based).

The Cyan coloured shoe was created using the Testacpscript (found in the script body above).

 

APASH01.PNG

 

I've never had this or seen this before. Has anyone seen this behaviour or know of a solution.

 

Cheers,

 

Steve

Reply
Reply
0 Likes
5,268 Views
23 Replies
Replies (23)
Message 2 of 24

jabowabo
Mentor
Mentor

It looks like your setpoint vector is wrong. try changing this:

s.setPoint((0.0, 0.0, inspoint), (-1.0, 0.0, 0.0))

to this:

s.setPoint((0.0, 0.0, inspoint), (0.0, -1.0, 0.0))

 

Edit:

Not sure if it makes a difference but I always make my setpoint origin at the center of pipe and translate the shoe to the outside of pipe. So my setpoint would look more like this:

 

s.setPoint((0.0, 0.0, 0), (0.0, -1.0, 0.0))
Reply
Reply
Message 3 of 24

Anonymous
Not applicable

Wonderful, thanks Jabowabo. That did the trick. I always get muddled up with setpoint cords......

 

I will remember your suggestion for next time for setpoints.

 

Cheers,

 

Steve

 
Reply
Reply
0 Likes
Message 4 of 24

Anonymous
Not applicable

sir,

I am also trying to write the custom script.

but i dont know where i am going wrong.

Can you guide me , 

actually where to write the script, we have to write in python sofware ( IDLE(python.gui) ) or ?

I tried to de-compile the available scripts in varmain folder and tried tried to modify as required and save as py

and tried to compile with python but no successfull.

please guide me

any material please  share

regards

krs

Reply
Reply
0 Likes
Message 5 of 24

Anonymous
Not applicable

Hi,

 

I'll try and keep this explanation as simple as possible.

 

  1. You will need to have a "CustomScripts" folder in your Shared Content area e.g. "C:\AutoCAD Plant 3D 2017 Content\CPak Common" or wherever yours is located. As per "C:\AutoCAD Plant 3D 2017 Content\CPak Common\CustomScripts". This is where all the Python scripts need to be.
  2. Load the "PnP3dACPAdapter.arx" from within Plant 3D.
  3. When finished writing the python scripts, they need to be compiled. To compile them you need to do it from inside Plant 3D. so, open Plant 3D, then from the command line issue this command "PLANTREGISTERCUSTOMSCRIPTS". This will compile the them and you will have a .PYC file for each .PY file. Errors will be shown if present and will need to be corrected.
  4. You will need to test the script in P3D to see if it will run or returns errors. I have attached a Python Script I wrote as an example. You will see two lines: (arxload "PnP3dACPAdapter") and (TESTACPSCRIPT "APAST02"). The second line which includes TESTASCRIPT needs to be run from the P3D command line. Just replace the name in quotes with the name of your script and run the whole command. E.G. Run (TESTACPSCRIPT "APAST02") on the command line. If all is OK you should get a 3D block in your drawing.
  5. With the previous drawing still open, issue the "PLANTSNAPSHOT" command and create images for you script to be shown in the Catalog. Put them in the "CustomScripts" when asked for a location.
  6. You can now add them to a Pipe Support Catalog and then a Pipe Support Spec. You can look up how to do this.
Reply
Reply
0 Likes
Message 6 of 24

Anonymous
Not applicable
Reply
Reply
0 Likes
Message 7 of 24

Anonymous
Not applicable

sir,

Firstly thank you very much.

I just copied your script as you said , it was compiled and necessary files were successfully created in the customscript folder.

but no block was created in the drawing.

When i tried to TESTACPSCRIPT "APAST02", through lisp as shown below. but no block is created in the active drawing.

am i missing any thing . guide me please

regards

image.png

Reply
Reply
0 Likes
Message 8 of 24

Anonymous
Not applicable

Do not try to run the lisp through the Visual Lisp editor, it will not work. You must be in Plant 3D and run the command from the AutoCAD command line.

 

Like this:

 

Command: (TESTASCRIPT "APAST02")

 

You should get a 3D block that looks like a tee post

Reply
Reply
0 Likes
Message 9 of 24

Anonymous
Not applicable

Excellent sir,

It is working and i got my mistake.

Thank you very much for your help

regards

 

Reply
Reply
0 Likes
Message 10 of 24

Anonymous
Not applicable

sir, what is the wrong with this script below

file is compiled without any error.

but no block is created when (TESTACPSCRIPT "______")

 

 

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

@Anonymous(Group="Support", TooltipShort="ST02 Tee Post Steel Mounted", TooltipLong="ST02 Tee Post Steel Mounted", LengthUnit="mm",Ports="1")
@matthias_hein("MainDimensions")
@param(D=LENGTH, TooltipShort="diamter", Ask4Dist=True)
@param(H=LENGTH, TooltipShort="Height of cylinder")
@matthias_hein(Name="meaningless enum")
@enum(1, "align X")
@enum(2, "align Y")
@enum(3, "align Z")
#-------------------------------------------------------------------
def KRS1(s, D = 200.0, H = 200.0, ID = 'KRS1', **kw):
R1 = D / 2.0
S=CYLINDER(s, R=R1, H=H, O=0.0)
s.setPoint((0.0, 0.0, 0.0), (0.0, 0.0, 1.0))

Reply
Reply
0 Likes
Message 11 of 24

Anonymous
Not applicable

Hi,

 

I have modified your code slightly. Please see below. If you compare the two you will see the difference. After the "def" statement the code needs to be indented. Also, the name of your script needs to match the name after the def statement. E.G. if the defined name is def KRS1, then you script needs to ne called KRS1, As does the ID=KRS1. All must match, or it will cause and error.

 

Hope this helps.

 

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

@Anonymous(Group="Support", TooltipShort="ST02 Tee Post Steel Mounted", TooltipLong="ST02 Tee Post Steel Mounted", LengthUnit="mm",Ports="1")
@matthias_hein("MainDimensions")
@param(D=LENGTH, TooltipShort="Diameter", Ask4Dist=True)
@param(H=LENGTH, TooltipShort="Height of Cylinder")
@matthias_hein(Name="meaningless enum")
@enum(1, "align X")
@enum(2, "align Y")
@enum(3, "align Z")
#(arxload "PnP3dACPAdapter")
#(TESTACPSCRIPT "KRS1")
#-------------------------------------------------------------------
def KRS1(s, D = 200.0, H = 200.0, ID = 'KRS1', **kw):
    R1 = (D / 2.0)
    Os = CYLINDER(s, R=R1, H=H, O=0.0)
    s.setPoint((0.0, 0.0, 0.0), (0.0, 0.0, -1.0))

Reply
Reply
Message 12 of 24

Anonymous
Not applicable

sir, 

firstly i thank you very much for guiding me. 

Now i am able to do some scripting.

But only one thing is , for testing the model, i have to close plant 3d and reopen, 

closing and opening the application takes much time for testing each and very script.

is there other way to test.

 

regards

 

Reply
Reply
0 Likes
Message 13 of 24

Anonymous
Not applicable
Open multiple sessions a plant. I do this all the time open Five or six sessions, test the script, close it, make a change to the script again in the next session open
Reply
Reply
0 Likes
Message 14 of 24

Anonymous
Not applicable

Dear sir,

Below is my definition line of the script.

 

import aqa.math
import math
from varmain.primitiv import *
from varmain.var_basic import *
from varmain.custom import *
@Anonymous(Group="VALVE", TooltipShort="ST02 Tee Post Steel Mounted", TooltipLong="ST02 Tee Post Steel Mounted", LengthUnit="mm",Ports="1")
@matthias_hein("MainDimensions")
@param(D=LENGTH, TooltipShort="Dia of valve", Ask4Dist=True)
@param(H=LENGTH, TooltipShort="Height of valve")
@param(L=LENGTH, TooltipShort="Lenght of valve")
@matthias_hein(Name="meaningless enum")
@enum(1, "align X")
@enum(2, "align Y")
@enum(3, "align Z")
#(arxload "PnP3dACPAdapter")
#(TESTACPSCRIPT "KRS1")
#-------------------------------------------------------------------
def VEGI2(s, D = 57.0, L = 130, H=400, ID = 'VEGI2', **kw):
T=H-(D+40)
G=H-(T-T/10-T/10-T/9)
B=T/2.5
o1=BOX(s, L=D+40, W=D+40, H=L-60)
o2=CYLINDER(s, R=D/2, H=30, O=0.0).rotateY(90).translate(((L-60)/2, 0.0, 0.0))
o3=CYLINDER(s, R=D/2, H=30, O=0.0).rotateY(-90).translate((-(L-60)/2, 0.0, 0.0))
o4=CYLINDER(s, R=D/2, H=H/10, O=0.0).translate((0.0, 0.0, (D+40)/2))
o5=CONE(s, R1=D/2, R2=D/2+20, H=T/9, E=0.0).translate((0.0, 0.0, ((D+40)/2+H/10)))
o6=CYLINDER(s, R=D/2+20, H=T/10, O=0.0).translate((0.0, 0.0, ((D+40)/2+H/10+T/9)))
o7=CYLINDER(s, R=0.75*D, H=G, O=0.0).translate((0.0, 0.0, ((D+40)/2+T/10+T/9+T/10)))
o8=CYLINDER(s, R=0.75*D+30, H=15, O=0.0).translate((0.0, 0.0, ((D+40)/2+T/10+T/9+T/10+G)))
o9=BOX(s, L=300, W=B, H=300).translate((0.0, 0.0, ((D+40)/2+T/10+T/9+T/10+G+15+B/2)))
o10=CYLINDER(s, R=70, H=300, O=0.0).rotateX(90).translate((100, 150, ((D+40)/2+T/10+T/9+T/10+G+15+B+70)))
o11=TORUS(s, R1=150, R2=7).rotateX(90).translate((-75, -155, ((D+40)/2+T/10+T/9+T/10+G+15+B-50)))
O12=CYLINDER(s, R=7, H=300, O=0.0).translate((-75, -155, ((D+40)/2+T/10+T/9+T/10+G+15+B-50-150)))
O13=CYLINDER(s, R=7, H=300, O=0.0).rotateY(90).translate((-75-150, -155, ((D+40)/2+T/10+T/9+T/10+G+15+B-50)))
s.setPoint((0.0, 0.0, 0.0), (0.0, 0.0, -1))

 

when i run the script and trying to export the script to the excel through catalog builder.

Only D & H  are appearing in the excel. But not the L. I dont know where i made the mistake.

please help me

regards

Konathala

 

Reply
Reply
0 Likes
Message 15 of 24

Anonymous
Not applicable

Dear sir,

i had created a script for valve ,tested and worked fine.

Object was added to catalog using catalog builder.

Later it was added to the spec.

I placed the component to the pipeline. Object is getting placed but ,

The line is continuous even after placing the component. pipe line is not 

cut after placing the component.

Kindly help where i am going wrong.

Code is as follows.

 

import aqa.math
import math
from varmain.primitiv import *
from varmain.var_basic import *
from varmain.custom import *
@Anonymous(Group="VALVE", TooltipShort="ST02 Tee Post Steel Mounted", TooltipLong="ST02 Tee Post Steel Mounted", LengthUnit="mm",Ports="1")
@matthias_hein("MainDimensions")
@param(D=LENGTH, TooltipShort="Dia of valve", Ask4Dist=True)
@param(H=LENGTH, TooltipShort="Height of valve")
@param(L=LENGTH, TooltipShort="Lenght of valve")
@matthias_hein(Name="meaningless enum")
@enum(1, "align X")
@enum(2, "align Y")
@enum(3, "align Z")
#(arxload "PnP3dACPAdapter")
#(TESTACPSCRIPT "KRS1")
#-------------------------------------------------------------------
def VEGI2(s, D = 57.0, L = 130, H=400, ID = 'VEGI2', **kw):
T=H-(D+40)
G=H-(T-T/10-T/10-T/9)
B=T/2.5
o1=BOX(s, L=D+40, W=D+40, H=L-60)
o2=CYLINDER(s, R=D/2, H=30, O=0.0).rotateY(90).translate(((L-60)/2, 0.0, 0.0))
o3=CYLINDER(s, R=D/2, H=30, O=0.0).rotateY(-90).translate((-(L-60)/2, 0.0, 0.0))
o4=CYLINDER(s, R=D/2, H=H/10, O=0.0).translate((0.0, 0.0, (D+40)/2))
o5=CONE(s, R1=D/2, R2=D/2+20, H=T/9, E=0.0).translate((0.0, 0.0, ((D+40)/2+H/10)))
o6=CYLINDER(s, R=D/2+20, H=T/10, O=0.0).translate((0.0, 0.0, ((D+40)/2+H/10+T/9)))
o7=CYLINDER(s, R=0.75*D, H=G, O=0.0).translate((0.0, 0.0, ((D+40)/2+T/10+T/9+T/10)))
o8=CYLINDER(s, R=0.75*D+30, H=15, O=0.0).translate((0.0, 0.0, ((D+40)/2+T/10+T/9+T/10+G)))
o9=BOX(s, L=300, W=B, H=300).translate((0.0, 0.0, ((D+40)/2+T/10+T/9+T/10+G+15+B/2)))
o10=CYLINDER(s, R=70, H=300, O=0.0).rotateX(90).translate((100, 150, ((D+40)/2+T/10+T/9+T/10+G+15+B+70)))
o11=TORUS(s, R1=150, R2=7).rotateX(90).translate((-75, -155, ((D+40)/2+T/10+T/9+T/10+G+15+B-50)))
O12=CYLINDER(s, R=7, H=300, O=0.0).translate((-75, -155, ((D+40)/2+T/10+T/9+T/10+G+15+B-50-150)))
O13=CYLINDER(s, R=7, H=300, O=0.0).rotateY(90).translate((-75-150, -155, ((D+40)/2+T/10+T/9+T/10+G+15+B-50)))
s.setPoint((L/2, 0.0, 0.0), (1.0, 0.0, 0.0))
s.setPoint((-L/2, 0.0, 0.0), (-1.0, 0.0, 0.0))

 

Reply
Reply
0 Likes
Message 16 of 24

Anonymous
Not applicable

Hi,

 

First of all you haven't stated what type of valve this is. If a flanged valve you will need to place a flange first the insert the valve. If it is a Buttweld valve then insert at end of pipe. All depends on how you have setup P3D.

 

However, I modified your code slightly as follows. Removed unnecessary lines and amended the names:

 

import aqa.math
import math
from varmain.primitiv import *
from varmain.var_basic import *
from varmain.custom import *
@Anonymous(Group="VALVE", TooltipShort="Custom Valve", TooltipLong="Custom Valve", LengthUnit="mm",Ports="1")
@matthias_hein("MainDimensions")
@param(D=LENGTH, TooltipShort="Dia of valve", Ask4Dist=True)
@param(H=LENGTH, TooltipShort="Height of valve")
@param(L=LENGTH, TooltipShort="Lenght of valve")
#(arxload "PnP3dACPAdapter")
#(TESTACPSCRIPT "VEGI2")
#-------------------------------------------------------------------
def VEGI2(s, D = 57.0, L = 130, H=400, ID = 'VEGI2', **kw):
T=H-(D+40)
G=H-(T-T/10-T/10-T/9)
B=T/2.5
o1=BOX(s, L=D+40, W=D+40, H=L-60)
o2=CYLINDER(s, R=D/2, H=30, O=0.0).rotateY(90).translate(((L-60)/2, 0.0, 0.0))
o3=CYLINDER(s, R=D/2, H=30, O=0.0).rotateY(-90).translate((-(L-60)/2, 0.0, 0.0))
o4=CYLINDER(s, R=D/2, H=H/10, O=0.0).translate((0.0, 0.0, (D+40)/2))
o5=CONE(s, R1=D/2, R2=D/2+20, H=T/9, E=0.0).translate((0.0, 0.0, ((D+40)/2+H/10)))
o6=CYLINDER(s, R=D/2+20, H=T/10, O=0.0).translate((0.0, 0.0, ((D+40)/2+H/10+T/9)))
o7=CYLINDER(s, R=0.75*D, H=G, O=0.0).translate((0.0, 0.0, ((D+40)/2+T/10+T/9+T/10)))
o8=CYLINDER(s, R=0.75*D+30, H=15, O=0.0).translate((0.0, 0.0, ((D+40)/2+T/10+T/9+T/10+G)))
o9=BOX(s, L=300, W=B, H=300).translate((0.0, 0.0, ((D+40)/2+T/10+T/9+T/10+G+15+B/2)))
o10=CYLINDER(s, R=70, H=300, O=0.0).rotateX(90).translate((100, 150, ((D+40)/2+T/10+T/9+T/10+G+15+B+70)))
o11=TORUS(s, R1=150, R2=7).rotateX(90).translate((-75, -155, ((D+40)/2+T/10+T/9+T/10+G+15+B-50)))
O12=CYLINDER(s, R=7, H=300, O=0.0).translate((-75, -155, ((D+40)/2+T/10+T/9+T/10+G+15+B-50-150)))
O13=CYLINDER(s, R=7, H=300, O=0.0).rotateY(90).translate((-75-150, -155, ((D+40)/2+T/10+T/9+T/10+G+15+B-50)))
s.setPoint((L/2, 0.0, 0.0), (1.0, 0.0, 0.0))
s.setPoint((-L/2, 0.0, 0.0), (-1.0, 0.0, 0.0))

 

See how you go with this.

Reply
Reply
0 Likes
Message 17 of 24

Anonymous
Not applicable

Dear sir,

in my script , i had mentioned

@Anonymous(Group="VALVE", TooltipShort="Check valve", TooltipLong="Check valve with offset ", LengthUnit="mm",Ports="2")

 and i had defined two set points at the end

s.setPoint((L/2, 0.0, 0.0), (1.0, 0.0, 0.0))
s.setPoint((-L/2, 0.0, 0.0), (-1.0, 0.0, 0.0))

 

still when address this pyc file to the catalog builder,

it is showing only D, H parameters, where there other parameters too,

and number of ports it is showing 1.

I cannot trace the problem.

help me 

regards

konathala

Reply
Reply
0 Likes
Message 18 of 24

Anonymous
Not applicable

Sir, 

I am waiting for your reply.

Kindly any one reply for my query

regards

konathala

Reply
Reply
0 Likes
Message 19 of 24

Anonymous
Not applicable

Dear sir,

This is my script, in which i tried to use stretch command

using line 

s.setLinearDimension('H', (0, 0, 0), (0, 0, -H))

but it is not working.

Kindly guide me where i am going wrong

regards

 

import aqa.math
import math
from varmain.primitiv import *
from varmain.var_basic import *
from varmain.custom import *
@Anonymous(Group="Support", TooltipShort="Single clamp saddle", TooltipLong="sliding support", LengthUnit="mm",Ports="1")
@matthias_hein("MainDimensions")
@param(D=LENGTH, TooltipShort="Diameter")
@param(H=LENGTH, TooltipShort="Height of Saddle", Ask4Dist=True)
@matthias_hein(Name="meaningless enum")
@enum(1, "align X")
@enum(2, "align Y")
@enum(3, "align Z")
#(arxload "PnP3dACPAdapter")
#(TESTACPSCRIPT "KRS1")
#-------------------------------------------------------------------
def TESTSTRE(s, D = 57.0, H=112.0, ID = 'TESTSTRE', **kw):
R1 = D / 2.0
o1=CYLINDER(s, R=R1, H=H, O=0.0)
s.setPoint((0.0, 0.0, 0.0), (0.0, 0.0, -1.0))
s.setLinearDimension('H', (0, 0, 0), (0, 0, -H))

Reply
Reply
0 Likes
Message 20 of 24

ARDIENTE.BEEJAY
Observer
Observer

Hi there,

 

I am new to this topic. I copied your script to start with. However when I try to test it I end up with an error

could you please guide me through 

 

The error is as follow

"Command: 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 "c:\autocad plant 3d 2017 content\cpak common\customscripts\TEST.py", line 8, in <module>
    @matthias_hein("MainDimensions")
NameError: name 'matthias' is not defined"

 

May I know the function of 

@matthias_hein

Reply
Reply
0 Likes