What's new

Selected Object Operations

KageDev

Member
This might be a stretch for the Alibre APIs capabilities, but does anyone know if it is possible to create a drawing from a selected design through the API? In the Design Explorer of Alibre it is nice to create 1x1 dxf files by having a design highlighted and then clicking the 'Make Drawing of this Design' button. My boss would like this process automated through the API but I haven't found any reference so far to know if this is possible. I've gotten to the point of highlighting an occurrence but that is the farthest I can get.
 

KageDev

Member
Is the template using the highlighted part, or is that separate? I need to make sure the part I select through my code is the one that the drawing is created from.
 

stepalibre

Alibre Super User
One way I thought to do it was with standard views, get the objects and read the view entities - pass them to a drawing object and then save the to file if possible.
 

stepalibre

Alibre Super User
Is the template using the highlighted part, or is that separate? I need to make sure the part I select through my code is the one that the drawing is created from.
It would be the active drawing I think unless you pass another drawing that's open to it.
 

NateLiquidGravity

Alibre Super User
I worked on this a bit in the past but ultimately moved on without finishing yet. There are a lot of abilities missing for the API in drawings and it also froze up when I tried to use specific named view orientations.
 

stepalibre

Alibre Super User
Great! And I can get the geo in the drawing session based on selection. I want to perform checks before I export to dxf to save work on the other side.
 

KageDev

Member
Wanted to update with my solution to this since I am developing my add-on with C#. Our company uses an M-Files Vault to store resources so that's why I have other API calls. I have a bunch of other code that relates to this that is not shown. Mainly just variables.
C#:
IADDrawingSession drawingSession = _alibreRoot.CreateEmptyDrawingEx("dxf creator", false);
IADSheet dxfSheet = drawingSession.Sheets.ActiveSheet;
string partPathRaw = vault.ObjectFileOperations.GetPathInDefaultView(objID, -1, fileID, -1);
string partPath = Regex.Replace(partPathRaw, @"\\", "/");
dxfSheet.CreateStandardViews(partPath, ADDrawingViewType.AD_STANDARD, ADDetailingOption.AD_PROJECT_FLAT_PATTERN, 1.0, 1.0, ADViewOrientation.AD_FRONT, drawingSession.GeometryFactory.Create2DPoint(0, 0));
checkedOut ??= vault.ObjectOperations.CheckOut(currentObj.ObjVer.ObjID);
FileVer newFile = vault.ObjectFileOperations.AddEmptyFile(checkedOut.ObjVer, objectVersionFile.ObjectVersion.VersionData.Title + " 1x1", "dxf");
string dxfPathRaw = vault.ObjectFileOperations.GetPathInDefaultView(checkedOut.ObjVer.ObjID, -1, newFile.ID, -1);
string dxfPath = Regex.Replace(dxfPathRaw, @"\\", "/");
drawingSession.ExportDXF(dxfPath);
drawingSession.Close();
vault.ObjectOperations.CheckIn(checkedOut.ObjVer);
 

bolsover

Senior Member
Wanted to update with my solution to this since I am developing my add-on with C#.
There are not too many here who have actually developed working add-on. Your work looks interesting - will you be making the full source code available to other users?
 

KageDev

Member
will you be making the full source code available to other users?
Yeah, I'm to the point with it where I could probably share it now and have people do whatever with the rest of the functionality. In a nutshell, the add on looks through the current session (So far just assembly sessions) and finds parts that are sheet metal parts. It will then look through M-Files too see if there is an existing CAD Pack (a custom folder my company uses) and then look into the CAD Packs to find a 1x1 dxf file. If either of the two are missing, the add-on prompts the user to create them. Once created or found it shows a list of the parts that are Laser Cut (defined in the M-Files properties) and gives the user the option to select which parts to export. I've completed up to the export portion where I will then need to figure out what my boss wants to do with the data. I believe the end goal is to get the data to an autonest program that best fits the parts to be laser cut by our in house laser cutter.

Current state of it shown here:
 
Last edited:
Top