
! script name: v3dinter.d/contintpart
! var_topic: contour intersect surface group with offset

!A
!A NAME:
!A
!A 	Contour Intersect Surface Group  with offset VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will generate a point at the intersection of a contour and
!A 	a surface group with an offset. The pick location will determine 
!A	which intersection is to be  generated.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CONTOUR: Pick the contour.
!B
!B 	PICK SURFACE GROUP: Pick the the surface group.
!B
!B	OFFSET FOR SURFACE GROUP: Enter the offset amount for surface group .
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: contour intersect part ")

DIM Destination$[256]
DIM Answer$[256]
DIM Contour$[256]
DIM Part_group$[256]
DIM Offset_var$[256]
DIM Name$[256]

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

Tol=NamedVarVal("3D Intersect Tol",Ws3DSystemVars,0.005)

Start:!

Intersect2:!

Pick_contour:!
Stat=SetPickMask(WsPickNoSurf)
Stat=SetInputFormat("n0","")
Contour=PickGroupEnt("PICK CONTOUR ")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Contour) THEN Pick_contour
Stat= EntityNameCheck(Contour,Contour$)

Stat=SetPickMask(WsPickSurfOnly)
Stat=SetInputFormat("n4a1",",N,")
Part_group=PickGroupEnt("PICK SURFACE GROUP, Name ",WsSurfaceGroup,Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$= "N" THEN
        GOSUB Get_named_group
END IF
IF NOT ValidDependency(Part_group) THEN Pick_loop
Stat= EntityNameCheck(Part_group,Part_group$)

Stat=SetPickMask(WsPickGeometry)
Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Offset)
Offset=GetValue("OFFSET FOR SURFACE GROUP")
IF ExitScript(Destination$) THEN Leave
No_offset_var= LastVariableInput(Offset_var$)
Normal_sign=1
Stat=SetPickMask(WsPickGeometry)


Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("GROUP: Contour intersect surface group")
Stat= SetRecDelLastExec
stat= Set3dInterOffset(0.0)
Stat= NullReference(Contour$)
Stat= NullReference(Part_group$)
V1= FreeParameter("Tolerance",Tol)
IF No_offset_var THEN
        V2= FreeParameter("Offset",Offset)
ELSE
        V2= FreeParameter("Offset",Offset_var$)
END IF
V3= FreeParameter("Normal sign",Normal_sign)
G1=ContourIntPart(Contour$,Part_group$,V1,V2,V3)
Stat= AutoNameGroup(G1,Name$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(G1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("intersect pts")
	Stat= AddGroupToUndo(WsUBCreateMode,G1,1,WsTrue)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Intersect2



Get_named_group:!
Stat=ListGrpNames("SURFACE GROUPS","selected group","",WsSurfaceGroup)
IF Stat=1 THEN Leave_name

Stat=SetInputFormat("a99","")
Stat=GetValue("SURFACE GROUP NAME",Answer$)

IF (ExitScript(Destination$)) THEN Leave
IF Answer$="CANCEL" THEN Leave_name
Part_group=FindNamedGrp(Answer$)
IF NOT ValidGeometry(Part_group) THEN Get_named_group
Grp_type= GroupType(Part_group)
IF Grp_type <> WsSurfaceGroup THEN Get_named_group
LowerSelectBox

Leave_name:!
Stat=SetInputFormat("n4","")

RETURN


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