📜 ⬆️ ⬇️

We read data from the open part of KOMPAS-3D files for integration with Pilot-ICE

KOMPAS-3D files contain information about the document: the name and designation of the drawing, the name of the developer checking and approving, the type of document, format, number of sheets. When an enterprise uses a system to automate workflow, the designer often has to enter this information manually.

image
Adding a document to the workflow system (Document Card)

The data to be entered into the card may already be in the source file, and therefore the input process can be automated.

')

Library for receiving data from KOMPAS-3D



Beginning with version 16 in the KOMPAS-3D data format, major changes have occurred. Firstly, it became more open, and secondly, the file size decreased. The format of KOMPAS-3D files version 16 and higher is a zip-archive that contains metadata in XML format with information about attributes and objects of this document. To read the KOMPAS-3D files, I developed the .NET library KompasFileReader , which is published under the MIT license [1].

Integration with the workflow system


We use Pilot-ICE as a workflow system. The algorithm of the user in the system is very simple. All the source files in the design are on a virtual disk Pilot-Storage, like Dropbox. If it is required to publish an electronic document and complete its approval, the Pilot-XPS virtual printer is used; as a result of printing, an electronic document is generated. The user selects a folder in the electronic archive and fills in the document card, then saves the document to the archive and coordinates it (if required). But if we work in the KOMPAS-3D system, correctly and accurately draw up the documents and as a result, fill out the main title of the drawing, we can automatically transfer the data from the main title to the Pilot-ICE document card. How to create such a plugin will be written below.

The Pilot-ICE system supports the ability to develop plug-ins, the SDK can be downloaded from the link in the download center [3].

You can create a new project according to the instructions from the SDK (Documentation.html).

In order to automatically fill out a document card, it is necessary to intercept the call to print a virtual printer and load a document card.

The plugin must use the IAutoImportHandler and IObjectCardHandler interfaces. To analyze the source file, you need to implement the IAutoImportHandler interface's Handle method, and also for filling the card, the method with the exact same interface name IObjectCardHandler.
Fragment of the plugin:
namespace Ascon.Pilot.SDK.KompasAttrAutoImport { [Export(typeof(IAutoimportHandler))] [Export(typeof(IObjectCardHandler))] public class KompasAttrAutoImport : IAutoimportHandler, IObjectCardHandler, ... { ... public bool Handle(string filePath, string sourceFilePath, AutoimportSource autoimportSource) { ... } public bool Handle(IAttributeModifier modifier, ObjectCardContext context) { ... } } } 


Retrieving and analyzing the source file


We intercept the path to the source file, which we print, we analyze the file and get its attributes.

 public bool Handle(string filePath, string sourceFilePath, AutoimportSource autoimportSource) { //        if (string.IsNullOrWhiteSpace(sourceFilePath)) return false; //    .  . if (!IsFileExtension(sourceFilePath, CDW_EXT) return false; using (var inputStream = new FileStream(sourceFilePath, FileMode.Open, FileAccess.Read)) { var ms = new MemoryStream(); inputStream.Seek(0, SeekOrigin.Begin); inputStream.CopyTo(ms); ms.Position = 0; if (IsFileExtension(sourceFilePath, SPW_EXT)) { var taskOpenSpwFile = new Task<SpwAnalyzer>(() => new SpwAnalyzer(ms)); taskOpenSpwFile.Start(); taskOpenSpwFile.Wait(); if (taskOpenSpwFile.Result.IsCompleted) { var spc = taskOpenSpwFile.Result.GetSpecification; spc.FileName = sourceFilePath; _doc = spc; } ... } ... } return false; } 


Filling the document card


Immediately after printing, a document card opens, intercepts its fields and fills them based on the data obtained above.
 public bool Handle(IAttributeModifier modifier, ObjectCardContext context) { var isObjectModification = context.EditiedObject != null; if (isObjectModification || context.IsReadOnly) return false; if (_doc == null) return false; var docProp = _doc.GetProps(); foreach (var pairPilotKompasAttr in _pairPilotKompasAttrs) { var val = docProp.FirstOrDefault(x => x.Name == pairPilotKompasAttr.NamePropKompas)?.Value; if (val != null) modifier.SetValue(pairPilotKompasAttr.NameAttrPilot, ValueTextClear(val)); } return true; } 


where _pairPilotKompasAttrs is a pair of attribute name values ​​in the Pilot ICE and KOMPAS-3D systems.
* Listings are given in a simplified form, you can see in more detail on the project page [1].

Demonstration of work


As an example, we take any drawing that is on the Pilot-Storage.

image
The drawing must be filled with the title block.

image
We print to a virtual printer.

image
Perfectly! The document card is filled automatically!

Plugin Setup


To adapt the plug-in to the configuration of your enterprise, we will provide the ability to customize the correspondence between the attributes of KOMPAS-3D and the attributes of the workflow system.
To do this, you can use the JSON format and store this data in the general system settings.

Settings example:
 [{ "NameAttrPilot": "name", "NamePropKompas": "" }, { "NameAttrPilot": "mark", "NamePropKompas": "" } ] 


where NameAttrPilot is the attribute name in the Pilot-ICE system, you can see it in Pilot-myAdmin,
NamePropKompas is the attribute name in the KOMPAS-3D system, you can find out by opening the KOMPAS-3D file as a zip-archive and examining the MetaInfo file.

References:



  1. Plugin for integration of the Pilot-ICE system with KOMPAS-3D - github.com/kozintsev/Pilot.CADReader .
  2. Pilot-ICE - a system for managing a project organization - pilotems.com .
  3. Download Center Pilot - pilot.ascon.ru .


Oleg Kozintsev

Source: https://habr.com/ru/post/347332/


All Articles