AutoCAD Plant 3D Forum
Welcome to Autodesk’s AutoCAD Plant 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Plant 3D topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Python Code Error Dimension

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
EddyWagner
274 Views, 3 Replies

Python Code Error Dimension

I'm having a problem with a Python code for creating an item in the catalog.

I tested the code and it works perfectly, however, one measurement is being altered by the plant.
The measurement of the flange, it makes it smaller than it actually should be.
If I test it here:

(arxload "PnP3dACPAdapter")
(testacpscript "CPVEW0002")
def CPVEW0002(s, D1=88.9, D2=88.9, D11=500, D22=500, D3=300.0, H1=150, L11=200.0, L22=200.0, B1=23.0, B2=23.0, P=2, **kw):

it does correctly, but if I do it through the catalog parameters, it comes out wrong.
It decreases the value of D11 and D22, which would be from the flanges.
Here is the code:

from varmain.primitiv import *
from varmain.custom import *
from aqa.math import * 
import math
@activate(Group="Instruments", TooltipShort="Visor", TooltipLong="Visor", FirstPortEndtypes="FL", LengthUnit="mm",  Ports="4")
# Parameters for Liner
@group("MainDimensions")
@param(D1=LENGTH, TooltipShort="Pipe OD", TooltipLong="Pipe OD")
@param(D11=LENGTH, TooltipShort="Flange OD", TooltipLong="Flange OD")
@param(D2=LENGTH, TooltipShort="Pipe OD", TooltipLong="Pipe OD")
@param(D22=LENGTH, TooltipShort="Flange OD", TooltipLong="Flange OD")
@param(D3=LENGTH, TooltipShort="Diametero Visor", TooltipLong="Diametero Visor")
@param(H1=LENGTH, TooltipShort="Altura Visor", TooltipLong="Altura Visor")
@param(L11=LENGTH, TooltipShort="Comp Conexão 01", TooltipLong="Comp Conexão 01")
@param(L22=LENGTH, TooltipShort="Comp Conexão 02", TooltipLong="Comp Conexão 02")
@param(B1=LENGTH, TooltipShort="# Flange", TooltipLong="C# Flange")
@param(B2=LENGTH, TooltipShort="# Flange", TooltipLong="# Flange")
@param(P=INT, TooltipShort="2 Para 02 portas", TooltipLong="3 Para 03 portas")
#PLANTREGISTERCUSTOMSCRIPTS
#(arxload "PnP3dACPAdapter")
#(testacpscript "CPVEW0002")
def CPVEW0002(s,D1=33.401,D2=33.401,D11=110,D22=110,D3=165.1,H1=137.922,L11=119.888,L22=119.888,B1=14.224,B2=14.224,P=2,**kw):

    bo1 = CYLINDER(s, R=D3/2, H=H1/2)    
    bo1N = CONE(s, R1=(D3 / 2) * .80, R2=(D3 / 2) * .90, H=(H1 / 2) *.4)
    bo1N.translate((0,0,H1*0.4))
    bo1N.erase()
    bo1.subtractFrom(bo1N)

    bo2 = CYLINDER(s, R=D3/2, H=H1/2)
    bo2N = CONE(s, R1=(D3 / 2) * .80, R2=(D3 / 2) * .90, H=(H1 / 2) *.4)
    bo2N.translate((0,0,H1*0.4))
    bo2.subtractFrom(bo2N)    
    bo2N.erase()
    bo2.rotateY(180)

    bo1.uniteWith(bo2)

    ent1 = CYLINDER(s, R=D1/2, H=L11)
    ent1b = CYLINDER(s, R=D11/2, H=B1)
    ent1b.translate((0,0,L11 - B1))
    ent1.uniteWith(ent1b)
    ent1.rotateY(-90)
    boSub1 = CYLINDER(s, R=D3/2, H=H1)
    boSub1.translate((0,0,-H1/2))
    ent1.subtractFrom(boSub1)  
    
    ent2 = CYLINDER(s, R=D1/2, H=L11)
    ent2b = CYLINDER(s, R=D11/2, H=B1)
    ent2b.translate((0,0,L11 - B1))
    ent2.uniteWith(ent2b)
    ent2.rotateY(-90).rotateZ(180)
    boSub2 = CYLINDER(s, R=D3/2, H=H1)
    boSub2.translate((0,0,-H1/2))
    ent2.subtractFrom(boSub2) 

    exit1 = CYLINDER(s, R=D2/2, H=L22)
    exit1b = CYLINDER(s, R=D22/2, H=B2)      
    exit1b.translate((0,0,L22 - B2))
    exit1.uniteWith(exit1b)
    exit1.rotateY(-90).rotateZ(90)
    boSub3 = CYLINDER(s, R=D3/2, H=H1)
    boSub3.translate((0,0,-H1/2))
    exit1.subtractFrom(boSub3) 

    exit2 = CYLINDER(s, R=D2/2, H=L22)
    exit2b = CYLINDER(s, R=D22/2, H=B2)      
    exit2b.translate((0,0,L22 - B2))
    exit2.uniteWith(exit2b)
    exit2.rotateY(-90).rotateZ(-90)
    boSub4 = CYLINDER(s, R=D3/2, H=H1)
    boSub4.translate((0,0,-H1/2))
    exit2.subtractFrom(boSub4) 
    
            
    if (P==4):
        Ports="4"
        bo1.uniteWith(ent1)
        bo1.uniteWith(ent2)
        bo1.uniteWith(exit1)
        bo1.uniteWith(exit2)
        s.setPoint((-L11,0,0),(-1,0,0))
        s.setPoint((L11,0,0),(1,0,0))
        s.setPoint((0,-L22,0),(0,-1,0))
        s.setPoint((0,L22,0),(0,1,0))
    elif (P==3):
        Ports="3"
        bo1.uniteWith(ent1)
        bo1.uniteWith(exit1)
        bo1.uniteWith(exit2)
        ent2.erase()
        s.setPoint((-L11,0,0),(-1,0,0))
        s.setPoint((0,-L22,0),(0,-1,0))
        s.setPoint((0,L22,0),(0,1,0))
    elif (P==22):
        Ports="2"
        bo1.uniteWith(ent1)
        bo1.uniteWith(ent2)
        exit1.erase()
        exit2.erase()
        s.setPoint((-L11,0,0),(-1,0,0))
        s.setPoint((L11,0,0),(1,0,0))
    else:
        Ports="2"
        bo1.uniteWith(ent1)
        bo1.uniteWith(exit1)
        ent2.erase()
        exit2.erase()
        s.setPoint((-L11,0,0),(-1,0,0))
        s.setPoint((0,-L22,0),(0,-1,0))
        
    return

 

I input the value of 107.95, and it changes to 101.6.
Any value close to 4", it will change to 4", which it shouldn't.
Is there something I could do to prevent this from happening? 

Tags (3)
3 REPLIES 3
Message 2 of 4
quan_hm
in reply to: EddyWagner

You have to set all these values to double type

def CPVEW0002(s,D1=33.401,D2=33.401,D11=110.0,D22=110.0,D3=165.1,H1=137.922,L11=119.888,L22=119.888,B1=14.224,B2=14.224,P=2.0,**kw):

 

Hoang Minh Quan - Piping design engineer
Autodesk Store for Python Catalog
Message 3 of 4
EddyWagner
in reply to: quan_hm

Hello @quan_hm ,

This approach really worked, although I don't understand the real reason why it doesn't automatically convert this value.
What is the purpose of "**kw" at the end and "s" at the beginning?

 

 

Additionally, we have your product here, and I'm just reporting a problem that I believe is from Autodesk. When adding an item created by your Spec in debug mode:

 

SpecPart specPart_Comp = ItemFind();
ObjectId symbolobjId_Comp = cm.GetSymbol(specPart_Comp, db, lUnit); // here there is a thread error

 

within Dispatcher:

 

[EditorBrowsable(EditorBrowsableState.Never)]
public void VerifyAccess()
{
if (!CheckAccess())
{
throw new InvalidOperationException(SR.Get("VerifyAccess"));
}
}

 

I don't want to prolong this because I know this is not the channel, just taking the opportunity to mention it since this should be an error from Autodesk for not implementing a try there...

Thank you for the solution.



Message 4 of 4
quan_hm
in reply to: EddyWagner

For your question about

What is the purpose of "**kw" at the end and "s" at the beginning?

**kw: this will allow any additional key-value pair for the function. Check this out: https://www.geeksforgeeks.org/args-kwargs-python/

"s": I suppose it's some kind of default class that have to pass to every function so that you can use s.setPoint, etc. 

The other thing if it's error due to my spec you can send me a DM or my email: quanhoang@khailongtech.com

Hoang Minh Quan - Piping design engineer
Autodesk Store for Python Catalog

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


AutoCAD Beta