
! script name: featureitems.d/placefeature
! topic: place feature

!A
!A NAME:
!A
!A 	Place Feature
!A
!A DESCRIPTION:
!A
!A	
!A
!B INSTRUCTIONS:
!B
!B
!B OPTIONS:
!B
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: place feature ")

DIM Answer$[1024],Destination$[1024]
DIM UniqName$[1024],ItemName$[1024]
DIM Namelist$[32000],Namelist2$[32000]
DIM Feat_name$[1024]
DIM Mdef_group$[1024],Hole_name$[1024],Center$[1024]
DIM Descr$[1024]

WsNamedComponent= 7041776
Workzone= CurrentComponent

DeActivateUndo
Start:!
PlanesGroup= FindNamedGrp("DIRECTION PLANES")
IF NOT ValidGeometry(PlanesGroup) THEN Leave

LargeGroup= FindNamedGrp("FIXTURE DIRECTIONS")
IF NOT ValidGeometry(LargeGroup) THEN Leave

Prop1= FindUserData("ITEMS GROUP LIST",WsMiscData)
IF NOT ValidGeometry(Prop1) THEN Leave

Q=0
Namelist$= ""
Num_grps= GroupCount(LargeGroup)
FOR K= 1 TO Num_grps                 ! Overall Group
    E1= GroupElement(LargeGroup,K)
    E2= GroupElement(PlanesGroup,K)
    FOR L= 1 TO GroupCount(E1)       ! Directional group
        E3= GroupElement(E1,L)
        FOR M= 1 TO GroupCount(E3)   ! Type inside the direction group
	  
	  Q= Q+1
	  Q2= GetUserValue(Prop1,"ITEM "&VAL$(Q)&":")

	  ItemsGrp= FindNamedGrp("FEATURE GROUP")
	  Item_ent= GroupElement(ItemsGrp,Q2)
	  IF NOT ValidGeometry(Item_ent) THEN Leave
	 
	  Feat_name$= UserDataStr(Item_ent,"Name:")

          Odata= FindUserData(Feat_name$,WsOperation)
          IF NOT ValidGeometry(Odata) THEN Next_m
          Stat= GetUserString(Odata,"Group name:",Mdef_group$)
          IF NOT ValidGeometry(Mdef_group$) THEN Next_m

          E7= GroupElement(E3,M)
	  FOR N= 1 TO GroupCount(E7)
		  E1a= GroupElement(E7,N)
		  IF EntityType(E1a)=WsCircleEnt THEN Got_circle
Next_n:	  NEXT N
Not_found:GOTO Next_m
Got_circle:Ig1= EntityItemGroup(E1a,WsDescending)
          Ig1c= GroupCount(Ig1)
          J= 1
          WHILE J<=Ig1c
             Prop_ig1= GroupElement(Ig1,J)
             IF J=1 THEN
                 G3a=GrpByProp(E2,Prop_ig1,UserDataType(Prop_ig1))
             ELSE
                 G3a2=GrpByProp(G3a,Prop_ig1,UserDataType(Prop_ig1))
                 Stat= DeleteEntity(G3a)
                 G3a=G3a2
             END IF
	     IF GroupCount(G3a)=1 THEN Got_surf
	     J= J+1
          END WHILE
Got_surf: Surface= GroupElement(G3a,1)
          L1=SurfNormalLine(Surface,0.5,0.5,1.0,WsForward)
          Ps= ParameterPt(L1,0.0)
          T1=LineToVertTrans(L1,Ps)
	  Stat= SetWorkplane(T1)
          Stat= DeleteEntity(L1)
          Stat= DeleteEntity(Ps)
          Stat= DeleteEntity(G3a)

	  EType= EntityType(E1a)
	  SELECT Etype
	  CASE WsCircleEnt
	    P1= CircleCenter(E1a)
	  CASE ELSE
	    P1= ParameterPt(E1a,0)
	    Dia= .5
          END SELECT
          G1=OperationHoles(P1,Mdef_group$)
	  Stat= SetComponent(G1,GetComponent(E1a))
          Odata= FindUserData(Feat_name$,WsOperation)
          Stat= AssocUserData(G1,Odata,WsOperation)
          Stat= DeleteEntity(G1)
	  Stat= DeleteEntity(P1)
No_luck:!
          Stat= DeleteEntity(Ig1)
Next_m: NEXT M
    NEXT L
NEXT K

LowerSelectBox

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