Kubotek Forum

KeyCreator & KeyCreator Viewer Technical discussion of CAD/CAM and integrated partner products
Customer Forum > KeyCreator & KeyCreator Viewer > Create an instance with one click View modes: 
User avatar
Advanced member
Advanced member
Soli - 9/13/2022 4:34:25 AM
   
Create an instance with one click
With this utility is possible to execute 3 commands with one click:
1. Save a view in model mode.
2. Automatically switch to last active layout.
3. Create an instance with the saved model view orientation.
It is possible to keep the last model view created, or to delete it.
The instance scale and the instance name can be entered in the dialog box.

===========================================================
//CHECK IF YOU ARE IN MODEL MODE
clear hLay
HLayout  hLay 
GetLayout  ,  hLay 
int error
error = @error
if (error == 0)
MessageBox "YOU ARE IN LAYOUT MODE.\nSWITCH TO MODEL MODE.\nPRESS OK", 0
if (error == 0)
exit
 
clear view_number , $instance_name 
int view_number
string $view_name
 
view_number = @dispview
GetDispViewName view_number, $view_name
if (view_number != 0)
goto dialog_box
 
SaveDispView  ""  , -1 , view_number
sprint $view_name , "VIEW %d" , view_number
SetDispViewName view_number, $view_name
 
:dialog_box
clear  nRows , nCols , nPlacement ,hDialog , $title
string  $title
int nRows = 14
int nCols = 68
int nPlacement = 4
int hDialog 
$title = "CREATE THE INSTANCE IN ACTIVE LAYOUT"
 
DG_RET_ON_SEL = 0x00000001
DG_CANCEL = 0x00000008
 
dg_init_dialog   nRows , nCols ,  , $title ,  ,  , nPlacement 
hDialog = @error
 
int nIndex =2
dYPos = 1
dXPos = 54
nColumns = 0
dg_add_button hDialog, nIndex, dYPos,  dXPos, nColumns, "&ABORT",  ,  , DG_CANCEL
 
int nIndex =3
dYPos = 1
dXPos = 2
nMaxWidth =16
double %dScale
 
dg_add_text_double  hDialog, nIndex  ,dYPos, dXPos , nMaxWidth, "%.3f"   ,    %dScale ,      ,     , 0
dYPos = dYPos-1
dg_add_title hDialog, nIndex, dYPos, dXPos, "INSTANCE SCALE"
 
int nIndex =4
dYPos = 10
dXPos = 25
nColumns = 0
dg_add_button hDialog, nIndex, dYPos,  dXPos, nColumns, "CREATE THE INSTANCE IN ACTIVE LAYOUT "
 
int nIndex =5
dYPos = 5
dXPos = 2
nMaxWidth =30
//string $view_name
dg_add_text_string  hDialog, nIndex  ,dYPos, dXPos , nMaxWidth,    ,    $view_name  ,      ,     , 0
dYPos = dYPos-1
dg_add_title hDialog, nIndex, dYPos, dXPos, "SAVED VIEW NAME"
 
int nIndex =6
dYPos = 5
dXPos = 36
nMaxWidth =30
int %bChecked
dg_add_check  hDialog, nIndex  ,dYPos, dXPos , %bChecked ,  "KEEP THE VIEW IN LIST VIEWS"  ,      ,     , 0
 
:dialog_box_run
 
dg_draw_dialog hDialog
dg_run_dialog hDialog
int index_result
index_result = @error
 
if (index_result == 2)
dg_erase_dialog hDialog  
if (index_result == 2)
dg_free_dialog hDialog 
if (index_result == 2)
exit
 
int nIndex = 3
dg_get_text_double hDialog , nIndex
%dScale = @error
 
int nIndex = 5
dg_get_text_string hDialog , nIndex
sprint $view_name , "%s" , @strdat
 
int nIndex = 6
dg_get_check hDialog , nIndex
%bChecked = @error
 
if (index_result == 4)
dg_erase_dialog hDialog  
if (index_result == 4)
dg_free_dialog hDialog 
 
//DIALOG BOX RESULTS
 
SetDispViewName view_number, $view_name
NOTESTATE
 
LayoutToggle
 
MessageBox "SELECT THE INSTANCE POSITION.\nPRESS OK", 0
 
CLEAR instance_position
DOUBLE instance_position[3]
type_pos=1
GETPOS "Select instance position", type_pos, adInstPos
if (@key == -3)
exit
 
int nMargin = 10
int dRotation = 0
int bBorder =1
int bCircular = 0
int bShowTangentLines = 1
int nRender = 1
//  0 Use Part Default values.
//  1 Wire-frame display
//  2 Hidden Line Removed display
//  3 Hidden Line Dashed display
//  4 Flat shaded display
//  5 Gouraud shaded display
//  6 Phong shaded display
int nWireRender = 0
int nThreadRender = 2
int nHLDisplayMethod = 2
 
NewDrawInst hNewInst ,    , adInstPos ,view_number , %dScale , nMargin , dRotation , $view_name , bBorder, bCircular, bShowTangentLines , nRender , nWireRender , nThreadRender , nHLDisplayMethod
NoteState
 
if (%bChecked == 1)
exit
DeleteDispView view_number
NoteState
MASKCLEAR
exit
=======================================================

The utility is based on the KXL command NewDrawInst.
I'm not sure when this command were added.
Possible in KC2022.

I'm used to delete the not standard views in model mode, because is very difficult
to work with a very long Views list.
If I need to recreate a deleted model view from the parameters of an instance
I use this utility:

==========================================================
clear hLay
HLayout  hLay 
GetLayout  ,  hLay 
int error = @error
if (error == -1)
pause "You are in MODEL mode ; Switch to LAYOUT"
if (error == -1)
exit
 
clear hInstance , $csName , adBaseMatrix
HDrawInst hInstance
string $csName 
DOUBLE adBaseMatrix[16] 
 
DrawInstSelect hInstance , 0x1 ,"SELECT THE INSTANCE"
 
GetDrawInstData hInstance ,   , rotation ,   ,   , adBaseMatrix ,   ,   , $csName  
if (rotation != 0)
MessageBox "CAN'T CREATE A MODEL VIEW.\nINSTANCE ROTATION HAS TO BE ZERO.\nPRESS OK", 0
if (rotation != 0)
EXIT
 
MessageBox "KC SWITCHES TO MODEL MODE AND CHANGES THE VIEW AS THE INSTANCE ORIENTATION.\nPRESS OK", 0
 
clear adView
DOUBLE adView[12] = {adBaseMatrix[0] , adBaseMatrix[1] , adBaseMatrix[2] , adBaseMatrix[4] , \
                                    adBaseMatrix[5] ,  adBaseMatrix[6] , adBaseMatrix[8] , adBaseMatrix[9] ,\
                                     adBaseMatrix[10] , adBaseMatrix[12] , adBaseMatrix[13] , adBaseMatrix[14] }
 
CLEAR adModelView
DOUBLE adModelView[12]
MatrixInvert adView ,  adModelView
 
LayoutToggle
 
SetDispView adModelView , -1
NOTESTATE
========================================================

Kubotek, what about to implement this idea in the program?


 

Solomon Steinberg,
Israel

DELL OPTIPLEX 7050
NVIDIA QUADRO P2000
KEYCREATOR 13.5
KEYCREATOR 2022 SP0



1
Login