What's new

expected ADExtendedDesignProperty, got ADExtendedDesignProperty?

kyleborot

Member
Hey all,

Dealing with a strange issue here. Can someone tell me what I'm doing wrong?

Python:
import sys
from getpass import getuser
from math import cos,sin,radians
from datetime import date
import AlibreX
import clr
clr.AddReferenceToFileAndPath(r'C:\Program Files\Alibre Design 28.0.1.28098\Program\AlibreX.dll')
from AlibreX import ADExtendedDesignProperty

# check minimum requirements
if AlibreScriptVersion < 1110:
  sys.exit('Please upgrade your copy of Alibre Design to use this script')



session = Global.Root.TopmostSession
part_session = session

doc_num = ADExtendedDesignProperty.AD_DOCUMENT_NUMBER
type = type(doc_num)
print(type)
for i in range(session.Configurations.Count):
    design_session = session.Configurations.Item(i).DesignSession
    properties = design_session.DesignProperties
    doc_number = properties.ExtendedDesignProperty(doc_num)

Here's my output:
Hey all,

Dealing with a strange issue here. Can someone tell me what I'm doing wrong?

Python:
import sys
from getpass import getuser
from math import cos,sin,radians
from datetime import date
import AlibreX
import clr
clr.AddReferenceToFileAndPath(r'C:\Program Files\Alibre Design 28.0.1.28098\Program\AlibreX.dll')
from AlibreX import ADExtendedDesignProperty

# check minimum requirements
if AlibreScriptVersion < 1110:
  sys.exit('Please upgrade your copy of Alibre Design to use this script')



session = Global.Root.TopmostSession
part_session = session

doc_num = ADExtendedDesignProperty.AD_DOCUMENT_NUMBER
type = type(doc_num)
print(type)
for i in range(session.Configurations.Count):
    design_session = session.Configurations.Item(i).DesignSession
    properties = design_session.DesignProperties
    doc_number = properties.ExtendedDesignProperty(doc_num)

Here's my output:
<type 'ADExtendedDesignProperty'>
Traceback (most recent call last):
File "<string>", line 32, in <module>
TypeError: expected ADExtendedDesignProperty, got ADExtendedDesignProperty

Any help is appreciated!
 

stepalibre

Alibre Super User
Without running the code, this happens when using AlibreX and AlibreScript in the same script. You might have an issue similar to that type ADExtendedDesignProperty is coming from AlibreScript but design_session is AlibreX. Type mix matching error.

Check your types and make sure they are compatible.
 

stepalibre

Alibre Super User
Without running the code, this happens when using AlibreX and AlibreScript in the same script. You might have an issue similar to that type ADExtendedDesignProperty is coming from AlibreScript but design_session is AlibreX. Type mix matching error.

Check your types and make sure they are compatible.
Also Python vs .NET vs IronPython types is another detail to look out for.
 

kyleborot

Member
Without running the code, this happens when using AlibreX and AlibreScript in the same script. You might have an issue similar to that type ADExtendedDesignProperty is coming from AlibreScript but design_session is AlibreX. Type mix matching error.

Check your types and make sure they are compatible.
Wouldn't this line
Python:
from AlibreX import ADExtendedDesignProperty
Prevent that issue? I am also not importing AlibreScripts.
 

stepalibre

Alibre Super User
Wouldn't this line
Python:
from AlibreX import ADExtendedDesignProperty
Prevent that issue? I am also not importing AlibreScripts.
Yes, but there are auto loaded objects for AlibreScript in the IPY session. I'm not saying this is the issue, only to check for type issues.
 

stepalibre

Alibre Super User
This typically mean a Python type:
<type 'ADExtendedDesignProperty'>
Not a .Net type coming from AlibreX.dll

And Global is a IPY/Python type coming from:
<com.alibre.automation.AlibreRoot object at 0x000000000000002B [com.alibre.automation.AlibreRoot]>

This is what I mean by type mix matching. Some issues are caused by this. Try to get the root from AlibreX object directly.

Sometimes this is not an issue because class, enum, and property names are the same and the returned type is also a correct match. But that's not always the case.
 

stepalibre

Alibre Super User
I made my Python Shell addon so it doesn't preload objects giving you a clean session to program:

1721758905438.png
It is possible to load Python scripts at startup.

AlibreScript has batteries included:

1721758945569.png
 

kyleborot

Member
This typically mean a Python type:
<type 'ADExtendedDesignProperty'>
Not a .Net type coming from AlibreX.dll

And Global is a IPY/Python type coming from:
<com.alibre.automation.AlibreRoot object at 0x000000000000002B [com.alibre.automation.AlibreRoot]>

This is what I mean by type mix matching. Some issues are caused by this. Try to get the root from AlibreX object directly.

Sometimes this is not an issue because class, enum, and property names are the same and the returned type is also a correct match. But that's not always the case.
Trying to get the root from AlibreX directy here:
Python:
alibre = Marshal.GetActiveObject("AlibreX.AutomationHook")
root = alibre.Root

I also import ADExtendedDesignProperty here through AlibreX

Python:
from AlibreX import ADExtendedDesignProperty

Still receiving the same problems, though.
 

stepalibre

Alibre Super User
The issue might be the API and not the code. Global.Root should work with AlibreX. I'll check if the API is working in C#.
 

stepalibre

Alibre Super User
Hey all,

Dealing with a strange issue here. Can someone tell me what I'm doing wrong?

Python:
import sys
from getpass import getuser
from math import cos,sin,radians
from datetime import date
import AlibreX
import clr
clr.AddReferenceToFileAndPath(r'C:\Program Files\Alibre Design 28.0.1.28098\Program\AlibreX.dll')
from AlibreX import ADExtendedDesignProperty

# check minimum requirements
if AlibreScriptVersion < 1110:
  sys.exit('Please upgrade your copy of Alibre Design to use this script')



session = Global.Root.TopmostSession
part_session = session

doc_num = ADExtendedDesignProperty.AD_DOCUMENT_NUMBER
type = type(doc_num)
print(type)
for i in range(session.Configurations.Count):
    design_session = session.Configurations.Item(i).DesignSession
    properties = design_session.DesignProperties
    doc_number = properties.ExtendedDesignProperty(doc_num)

Here's my output:
Hey all,

Dealing with a strange issue here. Can someone tell me what I'm doing wrong?

Python:
import sys
from getpass import getuser
from math import cos,sin,radians
from datetime import date
import AlibreX
import clr
clr.AddReferenceToFileAndPath(r'C:\Program Files\Alibre Design 28.0.1.28098\Program\AlibreX.dll')
from AlibreX import ADExtendedDesignProperty

# check minimum requirements
if AlibreScriptVersion < 1110:
  sys.exit('Please upgrade your copy of Alibre Design to use this script')



session = Global.Root.TopmostSession
part_session = session

doc_num = ADExtendedDesignProperty.AD_DOCUMENT_NUMBER
type = type(doc_num)
print(type)
for i in range(session.Configurations.Count):
    design_session = session.Configurations.Item(i).DesignSession
    properties = design_session.DesignProperties
    doc_number = properties.ExtendedDesignProperty(doc_num)

Here's my output:
<type 'ADExtendedDesignProperty'>
Traceback (most recent call last):
File "<string>", line 32, in <module>
TypeError: expected ADExtendedDesignProperty, got ADExtendedDesignProperty

Any help is appreciated!

This works:

Python:
import sys
import clr
clr.AddReference('System.Runtime.InteropServices')
from System.Runtime.InteropServices import Marshal
clr.AddReferenceToFileAndPath(r'C:\Program Files\Alibre Design 28.0.1.28098\Program\AlibreX.dll')
import AlibreX
alibre = Marshal.GetActiveObject("AlibreX.AutomationHook")
root = alibre.Root.TopmostSession
from AlibreX import ADExtendedDesignProperty
session = root
print(session.DesignProperties.ExtendedDesignProperty(ADExtendedDesignProperty.AD_DOCUMENT_NUMBER))

1721778951926.png

C#:
public class Program
{
    public static IADSession Session;
    public static IADPartSession CurrentPart;
    public static IAutomationHook Hook;
    public static IADRoot Root;
    public static void Main()
    {
        Hook = (IAutomationHook)Marshal.GetActiveObject("AlibreX.AutomationHook");
        Root = (IADRoot)Hook.Root;
        Session = Root.TopmostSession;
        CurrentPart = (IADPartSession)Session;
        var Output = CurrentPart.DesignProperties.ExtendedDesignProperty(AlibreX.ADExtendedDesignProperty.AD_DOCUMENT_NUMBER);
        Console.WriteLine(Output);
    }
}

I knew this worked from a recent rabbit hole:

Update your script to match and It should work. Try not to mix AlibreScript objects with AlibreX. They can work together in the same script, you just need to make sure types match.
 

NateLiquidGravity

Alibre Super User
@kyleborot I tested your script on v27 (simply because I had it open) and got an error that it could not import AlibreX. I removed the line import AlibreX and tried again and got no further errors. The same should have happened to you.
I can't say for certain but I suspect it is a problem with AlibreScript retaining AlibreX in memory from a previous script's import. I've had similar problems before and now I try to remember to fully close Alibre before final tests of a script.
 

stepalibre

Alibre Super User
I tested your script on v27 (simply because I had it open) and got an error that it could not import AlibreX. I removed the line import AlibreX and tried again and got no further errors. The same should have happened to you.
Yes, I reordered the lines before I rewrote it.
retaining AlibreX in memory from a previous script's import
I never experience that. It's always a type issue for me. But if you're programming in the AlibreScript addon, then yes objects persistent in the session. You'll need to close the AlibreScript addon and/or reset/restart the session. This is true in any Python session/console including my addon.
 

stepalibre

Alibre Super User
Nate is correct, this works fine after reordering import AlibreX in a restarted console. So a dirty session was the culprit.

1721781030430.png

I guess the error was caused by multiple session objects conflicting?
 
Last edited:

NateLiquidGravity

Alibre Super User
Just an FYI the Design Properties are all accessed simply in AlibreScript without having to use the AlibreX API.
Python:
#Get Enviroment---------- Thanks IDSLK
try:
    Enviroment = CurrentAssembly()
    EnviromentText = 'Assembly ' + str(Enviroment)
except:
    Enviroment = CurrentPart()
    EnviromentText = 'Part, Name: ' + str(self.Enviroment)
print(EnviromentText)
print(Enviroment.DocumentNumber)
I seem to remember there are a few properties that might not exist on parts and assemblies (materials at least) - so do be on the lookout for that.

If you are interested here is a complex tool I made for editing the properties of an assembly and its parts all at once:
https://www.alibre.com/forum/index.php?threads/release-properties_list-v2-0b.24546/post-168031
 

stepalibre

Alibre Super User
Just an FYI the Design Properties are all accessed simply in AlibreScript without having to use the AlibreX API.
Python:
#Get Enviroment---------- Thanks IDSLK
try:
    Enviroment = CurrentAssembly()
    EnviromentText = 'Assembly ' + str(Enviroment)
except:
    Enviroment = CurrentPart()
    EnviromentText = 'Part, Name: ' + str(self.Enviroment)
print(EnviromentText)
print(Enviroment.DocumentNumber)
I seem to remember there are a few properties that might not exist on parts and assemblies (materials at least) - so do be on the lookout for that.

If you are interested here is a complex tool I made for editing the properties of an assembly and its parts all at once:
https://www.alibre.com/forum/index.php?threads/release-properties_list-v2-0b.24546/post-168031
Thanks, Nate! I use .NET for properties, but I will use this asap for properties in some scripts. This is also useful in our other discussions on the forum.
I forgot AlibreScript had them.
The returned design properties are visible here:
Code:
Add3DSketch            AddAxis                AddChamfer
AddChamferAngle        AddConfiguration       AddExtrudeBoss
AddExtrudeCut          AddFillet              AddGear
AddGearDN              AddGearDP              AddGearNP
AddLoftBoss            AddLoftCut             AddParameter
AddPlane               AddPoint               AddPoints
AddRack                AddRevolveBoss         AddRevolveCut
AddSketch              AddSweepBoss           AddSweepCut
AddVertexChamfer       Axes                   Close
Comment                ConfigurationList      Configurations
CostCenter             CreatedBy              CreatedDate
CreatingApplication    Debug1                 Density
Description            DirectionType          DisplayUnits
DocumentNumber         Edges                  EndCondition
EngineeringApprovalDateEngineeringApprovedBy  Equals
EstimatedCost          ExportBIP              ExportIGES
ExportRotatedSTL       ExportSAT              ExportSTEP203
ExportSTEP214          ExportSTL              ExtendedMaterialInformation
Faces                  Features               FileName
FileTypes              Get3DSketch            GetActiveConfiguration
GetAxis                GetBoundingBox         GetConfiguration
GetCustomProperty      GetEdge                GetEdges
GetFace                GetFaces               GetFeature
GetHashCode            GetParameter           GetPlane
GetPoint               GetSelection           GetSelectionAssembly
GetSketch              GetType                GetUserData
GetVertex              GetVertices            HideFeature
IsOpen                 Keywords               LastAuthor
LastUpdateDate         ManufacturingApprovedByManufacturingApprovedDate
Mass                   Material               MemberwiseClone
ModifiedInformation    Name                   NonUniformScale
Number                 Origin                 ParameterList
Parameters             PauseUpdating          Planes
Points                 Product                ReceivedFrom
ReferenceEquals        Regenerate             RemoveFeature
RemovePlane            RemovePoint            RemoveSketch
ResumeUpdating         Revision               Save
SaveAs                 SaveSnapshot           SaveThumbnail
Scale                  Select                 Selections
SetColor               SetCustomProperty      SetUserData
ShowFeature            Sketches               Sketches3D
StockSize              Supplier               SuppressFeature
Title                  ToString               UnsuppressFeature
Vendor                 Vertices               WebLink
XAxis                  XYPlane                YAxis
YZPlane                ZAxis                  ZXPlane
_Part                  _SelectionSession      __class__
__delattr__            __doc__                __format__
__getattribute__       __hash__               __init__
__new__                __reduce__             __reduce_ex__
__repr__               __setattr__            __sizeof__
__str__                __subclasshook__
 

kyleborot

Member
Thanks, Nate! I use .NET for properties, but I will use this asap for properties in some scripts. This is also useful in our other discussions on the forum.
I forgot AlibreScript had them.
The returned design properties are visible here:
Code:
Add3DSketch            AddAxis                AddChamfer
AddChamferAngle        AddConfiguration       AddExtrudeBoss
AddExtrudeCut          AddFillet              AddGear
AddGearDN              AddGearDP              AddGearNP
AddLoftBoss            AddLoftCut             AddParameter
AddPlane               AddPoint               AddPoints
AddRack                AddRevolveBoss         AddRevolveCut
AddSketch              AddSweepBoss           AddSweepCut
AddVertexChamfer       Axes                   Close
Comment                ConfigurationList      Configurations
CostCenter             CreatedBy              CreatedDate
CreatingApplication    Debug1                 Density
Description            DirectionType          DisplayUnits
DocumentNumber         Edges                  EndCondition
EngineeringApprovalDateEngineeringApprovedBy  Equals
EstimatedCost          ExportBIP              ExportIGES
ExportRotatedSTL       ExportSAT              ExportSTEP203
ExportSTEP214          ExportSTL              ExtendedMaterialInformation
Faces                  Features               FileName
FileTypes              Get3DSketch            GetActiveConfiguration
GetAxis                GetBoundingBox         GetConfiguration
GetCustomProperty      GetEdge                GetEdges
GetFace                GetFaces               GetFeature
GetHashCode            GetParameter           GetPlane
GetPoint               GetSelection           GetSelectionAssembly
GetSketch              GetType                GetUserData
GetVertex              GetVertices            HideFeature
IsOpen                 Keywords               LastAuthor
LastUpdateDate         ManufacturingApprovedByManufacturingApprovedDate
Mass                   Material               MemberwiseClone
ModifiedInformation    Name                   NonUniformScale
Number                 Origin                 ParameterList
Parameters             PauseUpdating          Planes
Points                 Product                ReceivedFrom
ReferenceEquals        Regenerate             RemoveFeature
RemovePlane            RemovePoint            RemoveSketch
ResumeUpdating         Revision               Save
SaveAs                 SaveSnapshot           SaveThumbnail
Scale                  Select                 Selections
SetColor               SetCustomProperty      SetUserData
ShowFeature            Sketches               Sketches3D
StockSize              Supplier               SuppressFeature
Title                  ToString               UnsuppressFeature
Vendor                 Vertices               WebLink
XAxis                  XYPlane                YAxis
YZPlane                ZAxis                  ZXPlane
_Part                  _SelectionSession      __class__
__delattr__            __doc__                __format__
__getattribute__       __hash__               __init__
__new__                __reduce__             __reduce_ex__
__repr__               __setattr__            __sizeof__
__str__                __subclasshook__
Thank you both so much for all this information, it's really enlightening. As for AlibreScripts, is there a documented way to get the root from the configuration, kind of like how you can with AlibreX? I was trying to read the API, but this is all I saw for a Configuration Object.
Code:
"AlibreScript.API.Configuration.SetLocks(AlibreScript.API.LockTypes)","Sets the locks on the configuration"
"AlibreScript.API.Configuration.LockAll","Applies all locks to the configuration"
"AlibreScript.API.Configuration.UnlockAll","Removes all locks from the configuration"
"AlibreScript.API.Configuration.Activate","Makes the configuration active"
"P:AlibreScript.API.Configuration.Name","The name of the configuration"
"P:AlibreScript.API.Configuration.IsActive","True if the configuration is currently active"
Code:
"AlibreScript.API.GlobalParameters.GetConfiguration(System.String)","Gets a configuration with a specific name"
"AlibreScript.API.GlobalParameters.GetActiveConfiguration","Gets the currently active configuration"
 

bolsover

Alibre Super User
As for AlibreScripts, is there a documented way to get the root from the configuration, kind of like how you can with AlibreX? I was trying to read the API, but this is all I saw for a Configuration Object.
I don't see in the docs but I see this in the AlibreScript.API.Configuration code:
C#:
public IADConfiguration _Configuration;
public IADSession _Session;
public IADOccurrence _Occurrence;

You should be able to get the root from the _Session.
David
 

NateLiquidGravity

Alibre Super User
There are tons of ways to get to root. What exactly are you attempting to accomplish? Knowing that can really help us make suggestions.
 
Top