
! script name: vpksolids.d/vpkbsurfgroup
! var_solids: construct sheet bodies from synergy surface group

!A
!A NAME:
!A
!A 	Convert Surface Group	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will construct Sheet Bodies from a Synergy surface group.
!A
!B INSTRUCTIONS:
!B
!B	PICK GROUP: Pick the group of synergy surfaces to be converted.
!B
!B      GAP DISTANCE  No sew : Enter the maximum gap to be closed or
!B				turn off the sewing.
!B
!B      NUMBER OF ITERATIONS: Number of trials in the sewing process.
!B                            If the number of iterations is 1, only one trial
!B                            will be made using the input gap distance.
!B                            If the number of iterations is 2, then
!B                            the first trial will be at 1/2 the gap
!B                            distance, the second trial at the full
!B                            gap distance.
!C NOTES:
!C
!C	Can be used to convert existing surfaces into a parasolids
!C	sheet body.
!C
!# see also - htdocs/help.d/parasolids.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: convert surface group")

OPTION BASE 1
DIM Destination$[256]
DIM Answer$[256]
DIM A$[256]
DIM Title$[256]
DIM Name$[256]
DIM Label$[256]
DIM File$[256]
DIM Btype$[256]
DIM Name$[256]
DIM Group$[256]

Title$= "CONVERSION RESULTS"
File$= "tempdata"
Stat= RemoveFile(File$)


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

Stat= GLPlotOn

Units= CurrentUnits
IF Units= WsMetric THEN
	Gap_dist= 1.25
ELSE
	Gap_dist= .050
END IF
Stat= GLPlotOn

Pick_group:!
Stat=SetInputFormat("n4","")
Surf_group=PickGroupEnt("PICK GROUP")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Surf_group) THEN Pick_group
Stat= EntityNameCheck(Surf_group,Group$)

Gap_dist:!
Stat=SetInputFormat("a1n4=",",N,")
Stat=SetEqualsValue(Gap_dist)
Gap_dist=GetValue("GAP DISTANCE  No sew ",Answer$)
IF ExitScript(Destination$) THEN Leave

IF Answer$= "N" THEN
	Sew_bodies= WsFalse
ELSE
	Sew_bodies= WsTrue

Iterations:! Stat=SetInputFormat("n0=","")
	Stat=SetEqualsValue(1)
	Iterations=GetValue("NUMBER OF ITERATIONS")
	IF ExitScript(Destination$) THEN Leave

END IF

WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("SHEET: sheet from surface group")
G1= WPKMakeFromSurfGrp(Group$)
RecordFunctionOff
IF WPKErrorFlag THEN Sew_bodies= WsFalse
IF Sew_bodies THEN
	RecordFunctionOn
	V1= FreeParameter("Gap distance",Gap_dist)
	V2= FreeParameter("Number of iterations",Iterations)
	G2= WPKSewBodyList(G1,V1,V2)
	Stat= WPKNameBodyGroup(G2,Name$)
	Stat= WPKSetBodyParent(G2)
	Stat= DeleteEntity(G2)
	RecordFunctionOff
ELSE
	RecordFunctionOn
	Stat= WPKNameBodyGroup(G1,Name$)
	Stat= WPKSetBodyParent(G1)
END IF
RecordFunctionOn
Stat= DeleteEntity(G1)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("sheet from surface group")
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
WPKErrorCheck

GOTO Pick_group

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