
! script name: parasolids.d/mergesolidsfile
! solids: read a parasolids file

!A
!A NAME:
!A
!A 	Merge Solid File
!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	ROTATION ANGLE: Input the angle the model
!B 		is rotated about its zero.
!B
!B	PLACEMENT POINT: Give the location where
!B 		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 Name$[512]
DIM Mask$[512]
DIM Dir$[512]
DIM Dir1$[512]
DIM Default$[512]


ActivateUndo

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$))

Name$= Answer$


Ask_angle:!
Stat=SetInputFormat("n4="," ")
Stat=SetEqualsValue(Angle)
Angle=InputAngle("ROTATION ANGLE")
IF ExitScript(Destination$) THEN Leave

Next_dest:!
Pe=XyzInput("PLACEMENT POINT",WsXyzInput)
IF ExitScript(Destination$) THEN Leave

PlotOff
Ps= PointXYZ(0.0,0.0,0.0)
T1=AngleTransform(Ps,0,0,0,WsWorkplaneVals)
T2= InverseTrans(T1)
T3=AngleTransform(Pe,0,0,Angle,WsWorkplaneVals)
T4= MultTransforms(T3,T2)
Group= WPKMergeFile(Name$)
PlotOn
Stat=WPKTransBodyGrp(Group,T4)
Stat= DeleteEntity(Group)
Stat= DeleteEntity(Ps)
Stat= DeleteEntity(Pe)
Stat= DeleteEntity(T1)
Stat= DeleteEntity(T2)
Stat= DeleteEntity(T3)
Stat= DeleteEntity(T4)

ActivateUndo
Stat= AdvanceUndoNumber("merge solid file")
Stat= AddItemToUndo(WsUBPKSessionMark)
PlotAll
GOTO Ask_angle

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