What's new

Constraints to Assembly Planes

NateLiquidGravity

Alibre Super User
I'm trying to add constraints from a part to assembly planes.
Code:
assy = CurrentAssembly()
prt = assy.GetPart('New Part (1)<1>')
assy.AddAlignConstraint(0, assy, assy.XYPlane, prt, prt.XYPlane)
I get this error:
Microsoft.Scripting.ArgumentTypeException: expected IInstance, got Assembly
at Microsoft.Scripting.Interpreter.ThrowInstruction.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run8[T0,T1,T2,T3,T4,T5,T6,T7,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7)
at System.Dynamic.UpdateDelegates.UpdateAndExecute7[T0,T1,T2,T3,T4,T5,T6,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
at Microsoft.Scripting.Interpreter.DynamicInstruction`8.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
at AlibreScript.UI.IronTextBoxControl.#ijb(Object #9A)
I can constrain an AssembledPart to an AssembledSubAssembly but not the parent assembly. Is there a way this should work?
 
Last edited:

idslk

Alibre Super User
Hello Nate,

i would insert the first part into the assembly using offset and angle, then i would anchor this part or subassembly.
With the next part or subassembly you can use constraints how you like...
I think the addAlignContraint awaits (as the failure message and the reference says) an IInstance and the main assembly is not an IInstance of itself...

Regards
Stefan
 

albie0803

Alibre Super User
So at the moment you cannot insert a part into an assembly (at any level) and constrain it to a plane in the assembly.
 

albie0803

Alibre Super User
Exception:

Both these lines work in the included script

Assy.AddMateConstraint(0, Screw, Screw.YZPlane, P1, own_face)
Assy.AddMateConstraint(0, P1, own_face, Screw, Screw.YZPlane)

o_O:confused:
 

Attachments

  • Screws mate assembly.py
    17.8 KB · Views: 7

idslk

Alibre Super User
Hello albie0803,

opened a fresh assembly, inserted a demo part and started the downloaded skript.
got this console output:

M5
M5
Face<9>
Wuerfel
M5.0 x 30.0mm SHCS<1>
Microsoft.Scripting.ArgumentTypeException: expected IInstance, got Part

...

tested it 2 times with same result...

Regards
Stefan
 

NateLiquidGravity

Alibre Super User
Exception:

Both these lines work in the included script

Assy.AddMateConstraint(0, Screw, Screw.YZPlane, P1, own_face)
Assy.AddMateConstraint(0, P1, own_face, Screw, Screw.YZPlane)

o_O:confused:
Those planes are not 'owned' by the assembly. I'm talking about planes 'owned' by the assembly.
 

idslk

Alibre Super User
if you are not on beta, you can try the appended script.
It's only to test if it works...i changed/added a few lines after the face input...
So it does not recognize which instance of duplicates is selected(it checks if there are duplicates, but it will take the first part of the list...if somebody has interest...)
and so on and on...
Open an new assembly, insert an part (i've made me a cube for this...)and run the script...
Regards
Stefan
 

Attachments

  • Screws_mate_assembly_2018.py
    18.4 KB · Views: 4

idslk

Alibre Super User
i understood as said in #2, the #10 script is primary for albie0803 to may he wants to do his script before 2019 is released.
I think you're right with the enhancement request.

Regards
Stefan
 

NateLiquidGravity

Alibre Super User
I realized I never came back to publicly release my bug-fix-work-around for this.

I hacked together a class that inherits from Assembly and IInstance and fixed a missing function. I'm not sure if this will have any bad side effects but it seems to work fine in the few tests I ran here.
Python:
# '***  ConstraintsFixForAssembly                                                       ***'
# '***  by NateLiqGrav          7/4/2020                                                ***'
# '***   fix for top level assembly ref geometry not being able to be constrainted to   ***'
# '***   USE AT YOUR OWN RISK - THIS FIX IS COMPLETELY GUESSWORK ON MY PART             ***'
# '****************************************************************************************'
# '***   Example usage   ***'
# start_assem = CurrentAssembly()
# assem = MyBaseAssem(str(start_assem.Name), False) # accessed an already opened assembly by that name using the new class
# '****************************************************************************************'
class MyBaseAssem(Assembly, IInstance):
   def GetOccurrence(self):
       return self._Assembly.ActiveOccurrence
 
Last edited:

NateLiquidGravity

Alibre Super User
Again I hacked together a class that inherits from Assembly, IInstance, and now IAssembled to fix a missing function. AGAIN I'm not sure if this will have any bad side effects but it seems to work fine in the few tests I ran here. USE AT YOUR OWN RISK - THIS FIX IS COMPLETELY GUESSWORK ON MY PART! Alibre should really get the problem fixed internally so that we can constrain to the base assembly correctly!!!

Python:
# '***  ConstraintsFixForAssembly V28                                                   ***'
# '***  by NateLiqGrav          6/11/2024                                               ***'
# '***   fix for top level assembly ref geometry not being able to be constrainted to   ***'
# '***   USE AT YOUR OWN RISK - THIS FIX IS COMPLETELY GUESSWORK ON MY PART             ***'
# '****************************************************************************************'
# '***   Example usage   ***'
# start_assem = CurrentAssembly()
# assem = MyBaseAssem(str(start_assem.Name), False) # accessed an already opened assembly by that name using the new class
# '****************************************************************************************'
class MyBaseAssem(Assembly, IInstance, IAssembled):
   def GetOccurrence(self):
       return self._Assembly.ActiveOccurrence
   def GetMappedOccurrence(self, idk_lol):
       return self._Assembly.ActiveOccurrence
 
Top