
! script name: vitem.d/ptgrpcopyitem
! var_topic: Copy an item to the locations of a group of points.

!A
!A NAME:
!A
!A 	Copy a item to a group of points --- VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script make a new item at every location in a group of points.
!A
!B INSTRUCTIONS:
!B
!B 	PICK ENTITY: Select an entity in the item being copied.  If the entity
!B 	is contained in more than one item, a selection box will appear, where
!B 	you can choose the items you want copied.
!B
!B 	REFERENCE POINT: Enter the rotation reference point (i.e. the point the 
!B 	item  will be rotated around).
!B
!B
!# see also - htdocs/help.d/items.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: pt group copy item ")

DIM Answer$[256]
DIM Destination$[256]
DIM Pgroup$[256]
DIM Name$[256]
DIM Gname$[256]
DIM Item_name$[256]
DIM Center$[256]
DIM Class$[256]
DIM A$[256]
DIM B$[256]
DEG
Var_object= CheckVarObject
IF ExitScript(Destination$) THEN Leave

Highlight_color= 3
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)

DeActivateUndo
Start: !
Pick_entity:!
Stat= SetInputFormat("n4","")
E1=PickEntity("PICK ENTITY IN ITEM")
IF ExitScript(Destination$) THEN Leave

Group= EntityItemGroup(E1)
IF NOT ValidGeometry(Group) THEN Leave
Nitems= GroupCount(Group)
IF Nitems= 0 THEN Leave
IF Nitems=1 THEN
        Item_ent= GroupElement(Group,1)
        Id_number= UserDataType(Item_ent)
        Stat= DeleteEntity(Group)
        IF NOT ValidDependency(Item_ent) THEN Existing_items
ELSE
Existing_items:!
Stat=UserSelectBox("EXISTING ITEMS","Item selected",0,WsPropGroupSelect,Group)

Pick_item:!
        Stat=SetInputFormat("a99","")
        Stat=GetValue("INPUT ITEM ID NAME",Name$)
        IF (ExitScript(Destination$)) THEN Leave
        SELECT Name$
        CASE "CANCEL"
                 Stat= DeleteEntity(Group)
                 GOTO Start
        END SELECT

	Num1= NumericPrefix(Name$)
	IF NOT Num1 THEN Pick_item
        Item_ent= GroupElement(Group,Num1)
        IF NOT ValidDependency(Item_ent) THEN Start
        Stat= DeleteEntity(Group)
        LowerSelectBox
        Id_number= UserDataType(Item_ent)
END IF
stat= SetInputFormat("n4","")
Stat= SetSelectedFlag(Item_ent,WsTrue)
Stat= PlotEntity(Item_ent)
Stat= EntityNameCheck(Item_ent,Item_name$)

Ref_point:E2=PickEntity("REFERENCE POINT")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(E2) THEN Ref_point
Para1= LastPickPara
Pick_return1= CurrPickReturn
Stat= EntityNameCheck(E2,Center$)

Point_group:Pgroup=PickGroupEnt("SELECT POINT GROUP")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Pgroup) THEN Dest_point
Stat= EntityNameCheck(Pgroup,Pgroup$)

Stat= SetSelectedFlag(Item_ent,WsFalse)

Stat= GenerateVarName(WsGroupEnt,Gname$)
RecordFunctionOn
Stat= RecordDescr("COPY ITEM: position item at group of points")
RecordFunctionOn
SELECT Pick_return1
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,Para1,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,Para1,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,Para1,WsGeomCenter)
END SELECT
G1= PtGroupCopyItem(Item_name$,Pc,Pgroup$)
Stat= AutoNameItemGroup(G1,Gname$)
Stat= DeleteEntityList(Pc,G1)
RecordFunctionOff
CloseVarRecord

GOTO Start

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

