Decompile a Python file that comes with parametric graphics - AutoCAD Plant 3D

This article is a translation of the original text HERE.  

 

This article briefly describes how to find your own Python files and decompile them using third-party tools. 

  1. Find the built-in Python file 

Taking AutoCAD Plant 3D 2025 as an example, the corresponding parametric drawing file is under the installation path: 

C:\Program Files\Autodesk\AutoCAD 2025\PLNT3D\ContentScripts  

 

CGBenner_0-1765460340484.png

 

 

  1. Unzip the file 

Unzip the files in the variants.zip zip package 

  

  1. Find the cpb.pyc file 

varmain\arcsub\cpbsub  

 

CGBenner_1-1765460340485.png

 

 

  1. Use a third-party website to decompile PYC files 

Python decompilation tool  

  

  1. The result of decompilation 

 

CGBenner_2-1765460340486.png 

 

#!/usr/bin/env python
# visit https://tool.lu/pyc/ for more information
# Version: Python 3.11

from aqa.math import *
from varmain.arcsub.cpb_util import *
from varmain.primitiv import *
from varmain.var_basic import *

def CPB(s, D, D2, R, L2, L1, A, OF, ID = (114.3, 0, 175, 0, 0, 90, -1, 'CPB'), **kw):
    if R <= D / 2:
        R = D / 2 + 0.0001
    if D2 <= 0:
        D2 = D
    o0 = ARC3D2(s, D = D / 2, D2 = D2 / 2, R = R, A = A)
    Pts = CPB_CalcPts(o0, A, None, None)
    a1 = Pts[1]
    a0 = Pts[0]
    Pts4 = Pts[4]
    Pts5 = Pts[5]
    Pts6 = Pts[6]
    Pts7 = Pts[7]
    Pts = CPB_CalcPts(o0, A, L1 + a1 - a1, L2 + a0 - a0)
    HLeft = L2
    HRight = L1
    if HLeft <= R:
        Pts[5] = Pts5
        Pts[7] = Pts7
        HLeft = R * 0.01
        arc3d2TMP = CYLINDER(s, R = D * 0.01 / 2, H = R * 0.01).rotateY(-90).translate(Pts[8])
        arc3d2TMP.uniteWith(o0)
        o0.erase()
        o0 = arc3d2TMP
    else:
        arc3d2TMP = CYLINDER(s, R = D2 / 2, H = HLeft - a1).rotateX(-90).rotateZ(90 - A).translate(Pts[9])
        arc3d2TMP.uniteWith(o0)
        o0.erase()
        o0 = arc3d2TMP
    if HRight <= R:
        Pts[4] = Pts4
        Pts[6] = Pts6
        HRight = R * 0.01
    else:
        arc3d2TMP = CYLINDER(s, R = D / 2, H = HRight - a0).rotateY(90).translate(Pts[8])
        arc3d2TMP.uniteWith(o0)
        o0.erase()
        o0 = arc3d2TMP
    OF = getThickness(D = D, OF = OF)
    if OF > 0:
        O1 = getInsideDiameter(D = D, OF = OF)
        O2 = getInsideDiameter(D = D2, OF = OF)
        o1 = ARC3D2(s, D = O1 / 2, D2 = O2 / 2, R = R, A = A)
        o0.subtractFrom(o1)
        o1.erase()
    s.setPoint(Pts[4], Pts[6], 0)
    s.setPoint(Pts[5], Pts[7], 0)

activate(CPB, '\n[Type AQA-VCPB]\nVID=STRING,32\nDN=STRING\nD=LENGTH\nD2=LENGTH\nR=LENGTH\nA=ANGLE\nOF=LENGTH\nUnits=STRING,8\n;\nuniqId=CALC =$self.VID$ $self.DN$ $self.D2$ $self.A$\n;\nboltCalcVal=CALC CPB_GetNeededBoltParam(B1=0.0, B2=0.0, L1=-2, L2=-2)\n;\n@key=VID,DN\n', '@VarDataDefault0')


This article is a translation of the original text HERE.