
! script name: vpksolids.d/v3dpkembedsolid
! var_solids: embed a parasolids file

!A
!A NAME:
!A
!A 	Embed: File 3D Angles	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will merge a parasolids model into the current synergy
!A 	session.  Any other parasolid data already in the session will be
!A 	preserved.  This function allows for rotation and placement of
!A 	the model.
!A
!B INSTRUCTIONS:
!B
!B 	CHOOSE EXISTING FILE FROM FILE BOX: Choose the
!B 		parasolid file you wish to import from the file box.
!B
!B     X ANGLE: Enter the angle X axis orientation angle.
!B
!B     Y ANGLE: Enter the angle Y axis orientation angle.
!B
!B     Z ANGLE: Enter the angle Z axis orientation angle.
!B
!B 		The file is rotated first about the Y axis. Then
!B 		the result is rotated about the X axis. Then that
!B 		result is rotated about the Z axis.
!B
!B	PLACEMENT POINT: Give the location where the model is to be placed.
!B
!# see also - htdocs/help.d/parasolids.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: merge parasolids file ")

DIM Destination$[256]
DIM Answer$[256]
DIM Filename$[512]
DIM Name$[256]
DIM XAngle_var$[256]
DIM YAngle_var$[256]
DIM ZAngle_var$[256]
DIM Point$[256]
DIM Mask$[512]
DIM Dir$[512]
DIM Dir1$[512]
DIM Default$[512]

ActivateUndo
Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

Default$= "C:/usr/weber/ST/solids/"
Stat= NamedVarStr("solid file dir",WsSystemVars,Default$,Dir$)

	D_label$="DIRECTORY"
	Sub_label$="SUB DIRECTORIES"
	F_label$="FILES"
	Choice$="FILE TO OPEN"
	!           Mask$="[A-Za-z0-9]*"
	Mask$= "Parasolid Files (*.x_t)|*.x_t|"
        Mask$= Mask$&"Partition Files (*.par)|*.par|"
        Mask$= Mask$&"All Files (*.*)|*.*||"

	Stat=UserFileBox(Dir$,Mask$,D_label$,Sub_label$,F_label$,Choice$,"Synergy")
	Stat=SetInputFormat("a99","")
	Stat=GetValue("SELECT EXISTING JOB FILE",Answer$)
	IF (ExitScript(Destination$)) THEN Leave
	IF Answer$= "CANCEL" THEN Leave
	LowerFileBox
	IF NamedVarVal("save dirs",WsSystemVars,0) THEN V1=CreateVariable("solid file dir",WsSystemvars,PathNameDirectory(Answer$))

Filename$= Answer$


Angles3d:!
Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Xangle)
Xangle=GetValue("X AXIS ROTATION",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_xangle_var= LastVariableInput(Xangle_var$)
L1= LastPickEnt
IF ValidGeometry(L1) THEN
        IF NOT ValidDependency(L1) THEN Angles3d
        Stat= EntityNameCheck(L1,Xangle_var$)
        No_xangle_var=0
END IF

Stat=SetEqualsValue(Yangle)
Yangle=GetValue("Y AXIS ROTATION  ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_yangle_var= LastVariableInput(Yangle_var$)
L1= LastPickEnt
IF ValidGeometry(L1) THEN
        IF NOT ValidDependency(L1) THEN Angles3d
        Stat= EntityNameCheck(L1,Yangle_var$)
        No_yangle_var=0
END IF

Stat=SetEqualsValue(Zangle)
Zangle=GetValue("Z AXIS ROTATION  ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_zangle_var= LastVariableInput(Zangle_var$)
L1= LastPickEnt
IF ValidGeometry(L1) THEN
        IF NOT ValidDependency(L1) THEN Angles3d
        Stat= EntityNameCheck(L1,Zangle_var$)
        No_zangle_var=0
END IF

Next_dest:Stat=SetInputFormat("n4=","")
Pe=XyzInput("PLACEMENT POINT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pe) THEN Next_dest
E1= LastPickEnt
Pick_para= LastPickPara
Pick_return= CurrPickReturn
IF NOT ValidDependency(E1) THEN
        E1= CopyEntity(Pe)
        Stat= EntityNameCheck(E1,Point$)
        Pe_created= WsTrue
ELSE
        Stat= EntityNameCheck(E1,Point$)
        Pe_created= WsFalse
END IF
Stat=SetLastPoint(Pe)
Stat= DeleteEntity(Pe)

PlotOff
WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("EMBED SOLID: "&Filename$)
SELECT Pick_return
CASE WsGeometryEnd
        Pe= ParameterReturnPt(Point$,Pick_para,WsGeometryEnd)
CASE WsGeometryMid
        Pe= ParameterReturnPt(Point$,Pick_para,WsGeometryMid)
CASE WsGeomCenter
        Pe= ParameterReturnPt(Point$,Pick_para,WsGeomCenter)
END SELECT
IF No_xangle_var THEN
        V1= FreeParameter("X Angle",Xangle)
ELSE
        V1= FreeParameter("X Angle",Xangle_var$)
END IF
IF No_yangle_var THEN
        V2= FreeParameter("Y Angle",Yangle)
ELSE
        V2= FreeParameter("Y Angle",Yangle_var$)
END IF
IF No_zangle_var THEN
        V3= FreeParameter("Z Angle",Zangle)
ELSE
        V3= FreeParameter("Z Angle",Zangle_var$)
END IF
Ps= PointXYZ(0.0,0.0,0.0)
Trans1=AngleTransform(Ps,0,0,0,WsWorkplaneVals)
Trans2= InverseTrans(Trans1)
Trans3=AngleTransform(Pe,V1,V2,V3,WsWorkplaneVals)
Trans4= MultTransforms(Trans3,Trans2)
V4=StringConstant(Filename$)
Group= WPKMergeFile(V4)
PlotOn
Stat=WPKTransBodyGrp(Group,Trans4)
Stat= WPKNameBodyGroup(Group,Name$)
Stat= WPKSetBodyParent(Group)
Stat= DeleteEntityList(Group,Ps,Pe,Trans1,Trans2,Trans3,Trans4)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("3d embed solid")
IF Pe_created THEN Stat= AddItemToUndo(WsUBCreateMode,Point$)
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
WPKErrorCheck

GOTO Angles3d

Leave:!
PlotOn
Stat=SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
