Copy Source | Copy HTML uses ActiveX, Db, IniFiles, LDefin2D,LDefin3D, ksConstTLB, {$IFDEF __LIGHT_VERSION__} klTLB; {$ELSE} ksTLB, CheckLst; {$ENDIF} var kompas: KompasObject ; doc2: ksDocument2D ;
Copy Source | Copy HTML uses ActiveX, Db, IniFiles, LDefin2D,LDefin3D, ksConstTLB, {$IFDEF __LIGHT_VERSION__} klTLB; {$ELSE} ksTLB, CheckLst; {$ENDIF} var kompas: KompasObject ; doc2: ksDocument2D ;
Copy Source | Copy HTML uses ActiveX, Db, IniFiles, LDefin2D,LDefin3D, ksConstTLB, {$IFDEF __LIGHT_VERSION__} klTLB; {$ELSE} ksTLB, CheckLst; {$ENDIF} var kompas: KompasObject ; doc2: ksDocument2D ;
Copy Source | Copy HTML uses ActiveX, Db, IniFiles, LDefin2D,LDefin3D, ksConstTLB, {$IFDEF __LIGHT_VERSION__} klTLB; {$ELSE} ksTLB, CheckLst; {$ENDIF} var kompas: KompasObject ; doc2: ksDocument2D ;
Copy Source | Copy HTML uses ActiveX, Db, IniFiles, LDefin2D,LDefin3D, ksConstTLB, {$IFDEF __LIGHT_VERSION__} klTLB; {$ELSE} ksTLB, CheckLst; {$ENDIF} var kompas: KompasObject ; doc2: ksDocument2D ;
Copy Source | Copy HTML uses ActiveX, Db, IniFiles, LDefin2D,LDefin3D, ksConstTLB, {$IFDEF __LIGHT_VERSION__} klTLB; {$ELSE} ksTLB, CheckLst; {$ENDIF} var kompas: KompasObject ; doc2: ksDocument2D ;
Copy Source | Copy HTML uses ActiveX, Db, IniFiles, LDefin2D,LDefin3D, ksConstTLB, {$IFDEF __LIGHT_VERSION__} klTLB; {$ELSE} ksTLB, CheckLst; {$ENDIF} var kompas: KompasObject ; doc2: ksDocument2D ;
Copy Source | Copy HTML uses ActiveX, Db, IniFiles, LDefin2D,LDefin3D, ksConstTLB, {$IFDEF __LIGHT_VERSION__} klTLB; {$ELSE} ksTLB, CheckLst; {$ENDIF} var kompas: KompasObject ; doc2: ksDocument2D ;
Copy Source | Copy HTML uses ActiveX, Db, IniFiles, LDefin2D,LDefin3D, ksConstTLB, {$IFDEF __LIGHT_VERSION__} klTLB; {$ELSE} ksTLB, CheckLst; {$ENDIF} var kompas: KompasObject ; doc2: ksDocument2D ;
Copy Source | Copy HTML uses ActiveX, Db, IniFiles, LDefin2D,LDefin3D, ksConstTLB, {$IFDEF __LIGHT_VERSION__} klTLB; {$ELSE} ksTLB, CheckLst; {$ENDIF} var kompas: KompasObject ; doc2: ksDocument2D ;
Copy Source | Copy HTML
- // Create automation object KOMPAS_Graphic
- if Kompas = nil then begin
- {$ IFDEF __LIGHT_VERSION__}
- Kompas: = KompasObject ( CreateOleObject ('KompasLT.Application.5' ));
- {$ ELSE}
- Kompas: = KompasObject ( CreateOleObject ('Kompas.Application.5' ));
- {$ ENDIF}
- if Kompas <> nil then Kompas. Visible : = true;
- end;
- doc2: = ksDocument2D ( kompas.Document2D );
- if FileIsThere ( FileName ) then // FileName - template name + path
- doc2.ksOpenDocument ( FileName, false ) // Open the drawing
- else MessageBox ( self.Handle, Pchar (FileName ), 'File not found' , MB_OK);
- if doc2 <> nil then begin
- // HERE WE WORK WITH A DOCUMENT
- doc2.ksSaveDocument ( FileName1 ); // FileName1 - the name of the finished document + path
- end;
- // When we finish - Kompas: = nil;
Copy Source | Copy HTML
- var doc: ksDocument3D;
- doc2: ksDocument2D;
- Kompas: KompasObject;
Copy Source | Copy HTML
- begin
- // Create automation object KOMPAS_Graphic
- if Kompas = nil then
- begin
- {$ IFDEF __LIGHT_VERSION__}
- Kompas: = KompasObject ( CreateOleObject ('KompasLT.Application.5' ));
- {$ ELSE}
- Kompas: = KompasObject ( CreateOleObject ('Kompas.Application.5' ));
- {$ ENDIF}
- if Kompas <> nil then
- Kompas. Visible : = true;
- end;
- end;
Copy Source | Copy HTML
- begin
- if doc2d <> nil then doc2d: = nil;
- if doc3d <> nil then doc3d: = nil;
- if Kompas <> nil then begin
- // force close
- Kompas.Quit;
- Kompas: = nil;
- end ;
- end ;
Copy Source | Copy HTML
- Var
- part: ksPart; // Store our part here
- varCol: ksVariableCollection; // collection of variable details
- variable : ksVariable; // Active variable
- i, count : integer ; // Counters
- Patch: String; // Path to the template file
Copy Source | Copy HTML
- Begin
- Patch: = ExtractFilePath (Paramstr (0)) + 'draw \' ; // Templates in my "draw" directory
- if Kompas <> nil then begin
- if FileIsThere (Patch + FileName) then begin
- doc3d: = ksDocument3D (Kompas.Document3D);
- if doc3d <> nil then
- doc3d. Open (Patch + FileName, false );
- end else exit ;
- end else exit ;
- part: = ksPart (doc3d.GetPart (pTop_Part)); // first part in the assembly
- // in our case, our item.
- if part <> nil then begin
- // work with an array of external variables
- varCol: = ksVariableCollection (part.VariableCollection ());
- if varCol <> nil then
- begin
- variable : = ksVariable (kompas.GetParamStruct (ko_VariableParam));
- if variable = nil then exit ; // Check if there are any?
- count : = varCol.GetCount (); // Number of external variables
- for i: = 0 to count - 1 do // Run through all variables
- begin
- variable : = ksVariable (varCol.GetByIndex (i));
- // Look at the variable name, if our, then assign the value.
- if variable .Name = 'L1' then variable . Value : = StrToFloat (edL1.Text);
- if variable .Name = 'L2' then variable . Value : = StrToFloat (edL2.Text);
- if variable .Name = 'L3' then variable . Value : = StrToFloat (edL3.Text);
- if variable .Name = 'D1' then variable . Value : = StrToFloat (edD1.Text);
- if variable .Name = 'D2' then variable . Value : = StrToFloat (edD2.Text);
- if variable .Name = 'D3' then variable . Value : = StrToFloat (edD3.Text);
- end ;
- // Insert the specification here.
- part.needRebuild: = true ;
- part. Update ;
- part.RebuildModel (); // rebuilding the part model
- end ;
- end ;
- doc3d.treeNeedRebuild: = true ;
- doc3d.RebuildDocument; // rebuild the document model
- // Overwrite the file.
- doc3d. Save ;
- doc3d. close ; // Optionally ... I don't like it when a lot of things are open ...
- // For the cognitive moment, you can comment out.
- End ;
Source: https://habr.com/ru/post/91390/
All Articles