robertf said:
Are we still limited to c# and vb?
A long time ago in Excel (now 2010 version) I added AlibreX under tools -> references, for access to the API.
It seems to provide everything the API offers.
It was "wildcatting" (not the cat type) and the code I have may be sloppy and out of date but still used "a lot" to update constraint angles for spline plotting.
There is a flowchart for relationships among the documentation that explains a lot.
Something changed along the way that I fiddled around in a "watch" window to figure out but may have been conforming of the layout to the API with a new Alibre release.
So I have a "Microsoft Visual Basic for Applications" Module that starts with;
Code:
Public L01_PUoAD_Root As IADRoot ' Holds Alibre Root object
Public L02_PUoAD_Session As IADSession ' Holds Alibre Session Object
Public L03_PUoAD_Part As IADPartSession ' Holds Alibre Part Session object
Public L03_PUoAD_Assm As IADAssemblySession ' Holds Alibre Assembly Session Object
Public L04_MYoAD_assmConstraints As IADAssemblyConstraints ' Holds the Assembly constraint object enumeration
Public L05_MYoAD_assmConstraint As IADAssemblyConstraint ' Holds the Assembly constraint object
Public Const pcAD_Units_MILLIMETERS = ADUnits.ADUnits_AD_MILLIMETERS
Public Const pcAD_Units_CENTIMETERS = ADUnits.ADUnits_AD_CENTIMETERS
Public Const pcAD_Units_METERS = ADUnits.ADUnits_AD_METERS
Public Const pcAD_Units_INCHES = ADUnits.ADUnits_AD_INCHES
Public Const pcAD_Units_FEET = ADUnits.ADUnits_AD_FEET
' Public Const pcAD_POUNDMASS = ADUnits.AD_POUNDMASS
' ADUnits_AD_POUNDMASS = AlibreX.ADUnits_AD_POUNDMASS
Public Const pcAD_Units_POUNDMASS = AlibreX.ADUnits.ADUnits_AD_POUNDMASS
Public Const pcAD_ParameterTypeDISTANCE = ADParameterType.ADParameterType_AD_DISTANCE
Public Const pcAD_ParameterTypeANGLE = ADParameterType.ADParameterType_AD_ANGLE
Public Const pcAD_ParameterTypeCOUNT = ADParameterType.ADParameterType_AD_COUNT
Public Const pcAD_ParameterTypeSCALE = ADParameterType.ADParameterType_AD_SCALE
Public Const pcAD_SubType_ASSEMBLY = ADObjectSubType.ADObjectSubType_AD_ASSEMBLY
Public Const pcAD_SubType_BOM_TABLE = ADObjectSubType.ADObjectSubType_AD_BOM_TABLE
Public Const pcAD_SubType_CATALOG_FEATURE = ADObjectSubType.ADObjectSubType_AD_CATALOG_FEATURE
Public Const pcAD_SubType_DRAWING = ADObjectSubType.ADObjectSubType_AD_DRAWING
Public Const pcAD_SubType_EXTERNAL = ADObjectSubType.ADObjectSubType_AD_EXTERNAL
Public Const pcAD_SubType_PART = ADObjectSubType.ADObjectSubType_AD_PART
Public Const pcAD_SubType_SHEET_METAL = ADObjectSubType.ADObjectSubType_AD_SHEET_METAL
Public Const pcAD_SubType_SHEET_METALSHEET_METAL_CATALOG_FEATURE = ADObjectSubType.ADObjectSubType_AD_SHEET_METAL_CATALOG_FEATURE
Public Const pcAD_SubType_AD_SYMBOL = ADObjectSubType.ADObjectSubType_AD_SYMBOL
Public Const pcAD_SubType_3D_SKETCH = ADObjectType.ADObjectType_AD_3D_SKETCH
Public Const pcAD_SubType_3D_SKETCH_FIGURE = ADObjectType.ADObjectType_AD_3D_SKETCH_FIGURE
Public Const pcAD_SubType_AD_ASSEMBLY_CONSTRAINT = ADObjectType.ADObjectType_AD_ASSEMBLY_CONSTRAINT
Public Const pcAD_SubType_AD_BOM_COLUMN = ADObjectType.ADObjectType_AD_BOM_COLUMN
Public Const pcAD_SubType_BOM_ROW = ADObjectType.ADObjectType_AD_BOM_ROW
Public Const pcAD_SubType_AD_CONFIGURATION = ADObjectType.ADObjectType_AD_CONFIGURATION
Public Const pcAD_SubType_DATA_FONT = ADObjectType.ADObjectType_AD_DATA_FONT
Public Const pcAD_SubType_DESIGN_AXIS = ADObjectType.ADObjectType_AD_DESIGN_AXIS
Public Const pcAD_SubType_AD_DESIGN_PLANE = ADObjectType.ADObjectType_AD_DESIGN_PLANE
Public Const pcAD_SubType_DESIGN_POINT = ADObjectType.ADObjectType_AD_DESIGN_POINT
Public Const pcAD_SubType_DESIGN_SURFACE = ADObjectType.ADObjectType_AD_DESIGN_SURFACE
Public Const pcAD_SubType_DIMENSION = ADObjectType.ADObjectType_AD_DIMENSION
Public Const pcAD_SubType_EXPLODED_VIEW = ADObjectType.ADObjectType_AD_EXPLODED_VIEW
Public Const pcAD_SubType_EXPLODED_VIEW_STEP = ADObjectType.ADObjectType_AD_EXPLODED_VIEW_STEP
Public Const pcAD_SubType_FOLDER = ADObjectType.ADObjectType_AD_FOLDER
Public Const pcAD_SubType_FOLDER_ITEM = ADObjectType.ADObjectType_AD_FOLDER_ITEM
Public Const pcAD_SubType_GEOMETRY = ADObjectType.ADObjectType_AD_GEOMETRY
Public Const pcAD_SubType_OCCURRENCE = ADObjectType.ADObjectType_AD_OCCURRENCE
Public Const pcAD_SubType_PARAMETER = ADObjectType.ADObjectType_AD_PARAMETER
Public Const pcAD_SubType_PART_FEATURE = ADObjectType.ADObjectType_AD_PART_FEATURE
Public Const pcAD_SubType_REPOSITORY = ADObjectType.ADObjectType_AD_REPOSITORY
Public Const pcAD_SubType_ROLE = ADObjectType.ADObjectType_AD_ROLE
Public Const pcAD_SubType_ROOT = ADObjectType.ADObjectType_AD_ROOT
Public Const pcAD_SubType_SAVED_VIEW = ADObjectType.ADObjectType_AD_SAVED_VIEW
Public Const pcAD_SubType_SESSION = ADObjectType.ADObjectType_AD_SESSION
Public Const pcAD_SubType_SKETCH = ADObjectType.ADObjectType_AD_SKETCH
Public Const pcAD_SubType_SKETCH_FIGURE = ADObjectType.ADObjectType_AD_SKETCH_FIGURE
Public Const pcAD_SubType_TEAM = ADObjectType.ADObjectType_AD_TEAM
Public Const pcAD_SubType_TOPOLOGY = ADObjectType.ADObjectType_AD_TOPOLOGY
Public Const pcAD_SubType_UNKNOWN = ADObjectType.ADObjectType_AD_UNKNOWN
Public Const pcAD_SubType_USER = ADObjectType.ADObjectType_AD_USER
I may or may not have gotten all of those "Public" definitions correct or current but I didn't intend to ever release it so YMMV.
Just don't want to mislead anyone with unreviewed nomenclature.
(You can see there was a struggle to get "ADUnits_AD_POUNDMASS" back then. It may be a non-issue today but I think I got around it.)
Code:
Public Sub psAD_HookAlibre()
Dim My_Hook As IAutomationHook ' Holds Alibre Automation My_Hook object
Dim UserReply
On Error Resume Next
Set My_Hook = GetObject(, "AlibreX.AutomationHook")
If (My_Hook Is Nothing) _
Then ' Alibre Design is not initialized, report and quit
UserReply = MsgBox("Alibre Design is not running", 0, "Start Alibre")
Stop
Exit Sub
Else ' Alibre Design is initialized
Set L01_PUoAD_Root = My_Hook.Root
End If
If (L01_PUoAD_Root Is Nothing) Or (L01_PUoAD_Root.Sessions Is Nothing) _
Then ' for some reason an instance of Alibre Design or Alibre Session Object could not be found, report and quit
UserReply = MsgBox("Alibre My_Hook.root or .Sessions failed", 0, "Check Alibre")
Exit Sub
End If
End Sub
Code:
Public Sub psAD_FindADObject(MyWS_SessionTargetName As String, MyWS_SessionTargetType As String)
' Call psAD_FindADObject(VWSo_TargetSheet.Range("WS_SessionTargetName"), VWSo_TargetSheet.Range("WS_SessionTargetType")) 'EXAMPLE
Call psAD_HookAlibre
' From the WS extension literal determine what extension type is being sought and save the Alibre numeric type value
On Error GoTo 0
Dim My_SessionTargetType As ADObjectSubType
Dim UserReply, VBv_FileFound
If MyWS_SessionTargetType = "AD_PRT" _
Then ' looking for parts
My_SessionTargetType = pcAD_SubType_PART
Else
If MyWS_SessionTargetType = "AD_ASM" _
Then ' looking for assemblys
My_SessionTargetType = pcAD_SubType_ASSEMBLY
Else ' not a type used in this sub, report and quit
UserReply = MsgBox(MyWS_SessionTargetType & "Not a valid extension type for this option", 0, "Check Type AD_PRT or AD_ASM")
Stop
Exit Sub
End If
End If
' Session search
Dim MYoAD_EachSession As IADSession ' Holds "each" Alibre Session Object
VBv_FileFound = False ' Set the initial value
For Each MYoAD_EachSession In L01_PUoAD_Root.Sessions
If (MYoAD_EachSession.SessionType = My_SessionTargetType) _
Then ' It's the right file type
If MYoAD_EachSession.Name = MyWS_SessionTargetName _
Then ' It's the right file name
If VBv_FileFound _
Then ' this file has been found twice and the user may have 2 copies open, report and quit
UserReply = MsgBox("Two copies of " & MyWS_SessionTargetName & " found open", 0, "Close copy not opened from assembly")
Stop
Exit Sub
Else ' keep this Session
Set L02_PUoAD_Session = MYoAD_EachSession
VBv_FileFound = True
End If
End If
End If
Next
' Session search results
If VBv_FileFound _
Then ' set/copy the Alibre session object of the file type to its defined object type to use where needed
If My_SessionTargetType = pcAD_SubType_PART _
Then ' its a part Session
Set L03_PUoAD_Part = L02_PUoAD_Session
End If
If My_SessionTargetType = pcAD_SubType_ASSEMBLY _
Then ' its an assembly Session
Set L03_PUoAD_Assm = L02_PUoAD_Session
End If
Else ' this file was not found, report and quit
UserReply = MsgBox("The file """ & MyWS_SessionTargetName & """ is not open", 0, "Open the file")
End
Exit Sub
End If
End Sub
An example of what it can be used for was the following (which I don't use and haven't so long that it might not work).
If you know Excel you may recognize that I use "Named" cells or ranges. It was exploring for my own edification and not a "best practices" example either.
Code:
Sub RightArrow2_Click()
Set MYoWS_TargetSheet = ActiveSheet
Call psAD_FindADObject(MYoWS_TargetSheet.Range("WS_SessionTargetName"), MYoWS_TargetSheet.Range("WS_SessionTargetType"))
MYoWS_TargetSheet.Range("WS_ListAllEquations").Select
Set MYoWS_table = ActiveCell.CurrentRegion
MYoWS_table.Offset(1, 0).Resize(MYoWS_table.Rows.Count - 1, MYoWS_table.Columns.Count).ClearContents
MYoWS_TargetSheet.Range("WS_ListActiveConfig").Select
Dim MYoAD_DesignDetail As IADDesignSession ' Exposes one configurations detail in a design session
Set MYoAD_DesignDetail = L02_PUoAD_Session
Dim MYoAD_DesignProperties As IADDesignProperties ' Exposes ??????????? in a design session
Set MYoAD_DesignProperties = MYoAD_DesignDetail.DesignProperties
MYv_ConfigCount = MYoAD_DesignDetail.Configurations.Count
MYv_ActiveConfigName = MYoAD_DesignDetail.ActiveConfiguration.Name ' Save the active configuration name
MYoWS_TargetSheet.Range("WS_ConfigCount") = MYv_ConfigCount ' Report the configuration Count
Set MYoWS_TargetCell = MYoWS_TargetSheet.Range("WS_ListAllEquations")
MYv_TargetRow = 0
Dim MYv_Configurations As Integer
For MYv_Configurations = 0 To (MYv_ConfigCount - 1)
If MYv_ConfigCount > 1 _
Then ' there is more than one configuration so loop through each one from the first
Set MYoAD_DesignDetail.ActiveConfiguration = MYoAD_DesignDetail.Configurations.Item(MYv_Configurations) ' or use "= VADo_Config.DesignSession"
' L02_PUoAD_Session.Save
End If
If MYv_ActiveConfigName = MYoAD_DesignDetail.ActiveConfiguration.Name _
Then ' select this configuration to restore as active configuration if needed when done
MYv_RestoreConfiguration = MYv_Configurations
End If
' Refresh the link, Gets the alternate configuration or; if Alibre or the file go away, they stop run
Call psAD_FindADObject(MYoWS_TargetSheet.Range("WS_SessionTargetName"), MYoWS_TargetSheet.Range("WS_SessionTargetType"))
With Parameters
For Each Parameters In L02_PUoAD_Session.Parameters 'L01_PUoAD_Root.Sessions
MYoWS_TargetCell.Offset(MYv_TargetRow, -1) = MYoAD_DesignDetail.ActiveConfiguration.Name
MYoWS_TargetCell.Offset(MYv_TargetRow, 0) = .Name
MYoWS_TargetCell.Offset(MYv_TargetRow, 1) = .Equation
MYoWS_TargetCell.Offset(MYv_TargetRow, 2) = .Value
MYoWS_TargetCell.Offset(MYv_TargetRow, 3) = .Comment
MYoWS_TargetCell.Offset(MYv_TargetRow, 4) = .Type
MYoWS_TargetCell.Offset(MYv_TargetRow, 5) = .Units
MYoWS_TargetCell.Offset(MYv_TargetRow, 6) = .ExternallyDriven
MyChooseFormula = "=CHOOSE(" & .ParameterType & " + 1, ""Dist"", ""Angle"", ""Count"" & ""Scale"")"
MYoWS_TargetCell.Offset(MYv_TargetRow, 7) = MyChooseFormula
' ActiveCell.Offset(0, 8) = Parameters.Root
MYoWS_TargetCell.Offset(MYv_TargetRow, 8) = .SourceDocumentID
MYoWS_TargetCell.Offset(MYv_TargetRow, 9) = .SourceItemID
' jklh = L02_PUoAD_Session..Parameters.Item(0).comment
MYv_TargetRow = MYv_TargetRow + 1
Next
End With
Next MYv_Configurations
If MYv_ConfigCount > 0 _
Then ' there is more than one configuration so loop through each one from the first
If Not MYv_ActiveConfigName = MYoAD_DesignDetail.ActiveConfiguration.Name _
Then ' Restore active configuration when done
Set MYoAD_DesignDetail.ActiveConfiguration = MYoAD_DesignDetail.Configurations.Item(MYv_RestoreConfiguration)
' Refresh the link or; if Alibre or the file go away, they stop run
Call psAD_FindADObject(MYoWS_TargetSheet.Range("WS_SessionTargetName"), MYoWS_TargetSheet.Range("WS_SessionTargetType"))
End If
End If
hgiug = bodiesCount
'Set the object variable to Nothing.
Set fd = Nothing
End Sub
To preserve the original unedited files, first "save as", "Save all as" to a new folder before editing anything.
(Certainly if you run this it has potential to change files (configuration selection) - so don't save changes IMHO).
Another reason stuff like this doesn't get put out a lot :| .
If I had time, need or inclination a lot of "housekeeping" or review could be worked up using API's.
The nicest thing is that the "Microsoft Visual Basic for Applications" Modules work in any of the office applications I expect.
The VB code for the eagle parts list(?), etc. is up to their API access and/or your inclination or code skills.
I don't know if other software can use the "AlibreX" API as well but I suppose that is how Wizoscript gets in.
So, for "inserting" the answer seems to be yes if the API('s) allow.
YMMV