📜 ⬆️ ⬇️

We work with KOMPAS 3D from DELPHI continued (and the end)

imageimage Greetings,% username%.

And so probably I will finish this post what I started in the previous one. For, although time has passed a little, but the information began to slowly appear on the open spaces of the gossamer ...
In order not to take away the “piece of bread” from future authors, I will just finish what I started .


')
4.4. We work with the specification.

We will continue to work with the model. Next in line is clearance.
Immediately begin with the most (for me) confusing - the specification.

Copy Source | Copy HTML<br/>procedure TForm2.SetSpc (Nk:Integer; SSpec: String );<br/> var <br/> spc: ksSpecification;<br/> iter: ksIterator;<br/> obj, columnType, ispoln, blok: LongInt;<br/> count: Integer;<br/> spcColPar: ksSpcColumnParam;<br/> buf: string ;<br/>begin<br/> <br/> spc := ksSpecification(doc3d.GetSpecification); // . <br/> if spc = nil then exit;<br/> <br/> iter := ksIterator( kompas.GetIterator() ); // <br/> iter.ksCreateSpcIterator( '' , 0 , 0 ); // <br/> if iter.Reference <> 0 then begin // <br/> obj := iter.ksMoveIterator( 'F' ); // <br/> // <br/> count := spc.ksGetSpcTableColumn( '' , 0 , 0 );<br/> //kompas.ksMessage( Format( '- = %d', [ count ] ) ); // <br/> <br/> spcColPar := ksSpcColumnParam( kompas.GetParamStruct(ko_SpcColumnParam) );<br/> if spcColPar<>nil then<br/> if spc.ksGetSpcColumnType( obj, // <br/> 4 , // , 1, <br/> spcColPar ) <> 0 then begin <br/> // , "" <br/> columnType := spcColPar.columnType; <br/> ispoln := spcColPar.ispoln;<br/> blok := spcColPar.block;<br/> // ( , ) <br/> buf := spc.ksGetSpcObjectColumnText( obj, columnType , ispoln, blok );<br/> <br/> //kompas.ksMessage( buf ); //, ( ) <br/> spc.ksSpcObjectEdit(obj); // . <br/> if spc.ksSetSpcObjectColumnText(columnType,ispoln, blok , SSpec)<> 1 then<br/> ShowMessage( ' ' ); // <br/> spc.ksSpcObjectEnd(); // <br/> //buf := spc.ksGetSpcObjectColumnText( obj, columnType , ispoln, blok ); <br/> //kompas.ksMessage( buf ); // ( ) <br/> end;<br/> <br/> //obj := iter.ksMoveIterator( 'N' ); // <br/> // <br/> end;<br/>end;<br/> <br/>


4.5. We work with the name of the part.

It's all much easier.
We have the variable part: ksPart;
part.marking: = 'Part Name'; // Call the part.

4.6. We work with a drawing.

This item is quite extensive.
But in the process of writing this part of the article, I absolutely accidentally googled the link . "Accidents are not accidental" (c)
There is a good “analysis” of work with the drawings and their elements. ( main page of the topic )
In this regard, the number of my "outflows" has decreased dramatically. Because the template drawing is parameterized here, then when the part is resized, the projection automatically changes and changes accordingly to the correct dimensions.
To open the template, we also will not be difficult:

Copy Source | Copy HTML<br/> if Kompas = nil then begin<br/> {$IFDEF __LIGHT_VERSION__}<br/> Kompas:= KompasObject( CreateOleObject( 'KompasLT.Application.5' ) );<br/> {$ELSE}<br/> Kompas:= KompasObject( CreateOleObject( 'Kompas.Application.5' ) );<br/> {$ENDIF}<br/> if Kompas <> nil then Kompas.Visible := true ;<br/>end;<br/> <br/>doc2d:= ksDocument2D( kompas.Document2D );<br/> if FileIsThere(Path+ '\'+FileName) then <br/> doc2d.ksOpenDocument(Path+' \ '+FileName,false) // <br/> else Kompas.ksMessage(' - '+FileName); <br/>


5. Small "workarounds". Or not always bad advice.


5.1. Drawing template - instead of a model template.

In my, not completely sophisticated look, with a large number of parts of the same type, each of which requires a separate working drawing, it is convenient to use the filling in of a template created directly from the drawing.
Thus, we reduce the amount of “redundant” data on the hard disk, increase the processing speed (with more than 100 drawings, this is quite critical).
(In fact, this is not an absolutely correct method, it is easier to create one drawing with a table of sizes. But in 90% of cases we are obliged to satisfy the customer’s desire, if this does not contradict our moral and ethical principles, and it is not possible to convince him in a “peaceful” way)
Make a template is quite simple. To do this, you need to split the views (in order to decouple from the model) and replace the size values ​​with a template name. Example: ,,,,,.
Then we simply change the dimensions directly in the drawing.
Well, of course, that "just" is a relative concept.
And we again take on the "favorite" iteration, which takes not too much time and additional computer resources.

Copy Source | Copy HTML<br/>function TForm2.DrawWD: Boolean ;<br/> var Iter: ksIterator;<br/> param:ksDimTextParam;<br/> iDimParams : ksLDimParam; // <br/> arr:ksDynamicArray;<br/> textLine : ksTextLineParam;<br/> textItem : ksTextItemParam;<br/> i, ref :Integer;<br/> kStr:ksChar255; // )) <br/>begin<br/> Result:=False;<br/> Iter:=ksIterator(Kompas.GetIterator); // <br/> If Iter.ksCreateIterator(LDIMENSION_OBJ, 0 )=False then exit;<br/> // <br/> <br/> ref :=Iter.ksMoveIterator( 'F' );<br/> if Doc2.ksExistObj( ref )= 1 then<br/> repeat // <br/> <br/> iDimParams := ksLDimParam(Kompas.GetParamStruct(ko_LDimParam));<br/> textLine := ksTextLineParam( kompas.GetParamStruct( ko_TextLineParam) );<br/> textItem := ksTextItemParam( kompas.GetParamStruct(ko_TextItemParam) );<br/> if ( (iDimParams = nil) Or (textLine = nil) Or (textItem = nil) ) then Exit;<br/> Doc2.ksGetObjParam( ref , iDimParams, ALLPARAM); // <br/> param := ksDimTextParam( iDimParams.GetTPar ); // <br/> if param = nil then Exit;<br/> arr := ksDynamicArray( param.GetTextArr ); // <br/> if arr = nil then Exit;<br/> <br/> kStr:=ksChar255(kompas.GetParamStruct(ko_Char255));<br/> for I := 0 to arr.ksGetArrayCount - 1 do begin // <br/> arr.ksGetArrayItem(i,kStr);<br/> <br/> if '<L1>' =kStr.str then kStr.str:=Format( '%1.1f' ,[L1]);<br/> if '<L2>' =kStr.str then kStr.str:=Format( '%1.1f' ,[L2]);<br/> if '<L3>' =kStr.str then kStr.str:=Format( '%1.0f' ,[L3]);<br/> <br/> if '<D1>' =kStr.str then kStr.str:=Format( '%1.0f' ,[D1]);<br/> if '<D2>' =kStr.str then kStr.str:=Format( '%1.0f' ,[D2]);<br/> if '<D3>' =kStr.str then kStr.str:=Format( '%1.1f' ,[D3]);<br/> // (/) Format() <br/> <br/> arr.ksSetArrayItem(i,kStr); // <br/> end;<br/> <br/> param.SetTextArr(arr); // <br/> iDimParams.SetTPar(param); // <br/> <br/> doc2.ksSetObjParam( ref ,iDimParams,ALLPARAM); // . <br/> <br/> ref :=Iter.ksMoveIterator( 'N' );<br/> until Doc2.ksExistObj( ref )= 0 ;<br/> Iter.ksDeleteIterator;<br/> <br/> doc2.ksRebuildDocument;<br/> Result:=True;<br/>end;<br/> <br/>

The example is purely nominal, but crammed with two hours of “debriefing” descriptions ...

5.2. Get rid of the "extra gestures".

In the drawing, it is often necessary to change not only the size, but also some text (for example: Number_of_plan, Customer, Number of products).
In order not to “run through” the elements of the drawing again, but with reference to the text objects of the drawing, instead of text, you can create these inscriptions as dimension values:
Create a linear dimension in the free space of the drawing. Replace the size value with a generic name. In the size properties, remove the extra lines and arrows.
Now, when “jogging” in size, we can also replace the text in the drawing.
By the way, we can use this technique to bring some other types of dimensions to linear dimensions.

5.3. And a bit more.

When designing full-fledged products and customer requirements "to ensure all design documentation," it is enough just to create a template (s) for a complete set of documentation. Before processing, copy them to a separate working folder, and after finishing work, copy them to the folder with the corresponding project (product) name.
The procedure for copying is terribly simple. I use the following:

Copy Source | Copy HTML<br/>uses ShellApi;<br/> <br/>function CopyDir( const fromDir, toDir: string ): Boolean ;<br/> var <br/> fos: TSHFileOpStruct;<br/>begin<br/> ZeroMemory(@fos, SizeOf(fos));<br/> with fos do <br/> begin<br/> wFunc := FO_COPY;<br/> fFlags := FOF_FILESONLY;<br/> pFrom := PChar(fromDir + # 0 );<br/> pTo := PChar(toDir)<br/> end;<br/> Result := ( 0 = ShFileOperation(fos));<br/>end; <br/>


In fact, the “pitfalls” both in KOMPAS 3D itself and in programming for it, much more, so far I remember only those. If I remember, it will be UPDATE.

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


All Articles