
! script name: v3dinter.d/entintpart
! var_topic: entity intersect part group

!A
!A NAME:
!A
!A 	Entity Intersect Part VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will generate points at the intersection of an entity and
!A 	a part. The pick location will determine which intersection is to be
!A 	generated.
!A
!B INSTRUCTIONS:
!B
!B 	PICK ENTITY: Pick the entity.  Note: The pick location is important.
!B
!B 	PICK PART: Pick the the surface.  Note: The pick location is
!B 		important.
!B
!C NOTES:
!C
!C 	The pick location should be near the desired intersection, failure
!C 	to do this may result in no point generated.
!C

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

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

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

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

ActivateUndo
Intersect2: !

Pick_entity:!
Stat=SetPickMask(WsPickNoSurf)
Stat=SetInputFormat("n0","")
E1=PickEntity("PICK ENTITY ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(E1) THEN Pick_entity
Stat= EntityNameCheck(E1,Element$)
T=LastPickPara

Pick_surf:!
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=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("POINT: Entity intersect part")
Stat= SetRecDelLastExec
stat= Set3dInterOffset(0.0)
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(Element$,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=DeleteEntity(UVpoint)
Stat=SetPickMask(WsPickGeometry)
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
