Jump to content
Developer Wiki and Function Reference Links ×

search symbolname with a wildcard *


Recommended Posts

Dear maarten,

i used now a listbox. the listbox will be filled with the layers.

but how can i now give the selected layers to my searchstring?

PROCEDURE HANDLEOK;
BEGIN

    ALLOCATE DynWahlLayer[0..posSel+1];
counter := 0;
posSel := 0;

GetSelChoice(7,posSel,position,WahlLayer);
DynWahlLayer[counter] := WahlLayer;
REPEAT
counter := counter+1;
posSel := posSel+1;
GetSelChoice(7,posSel,position,WahlLayer);
DynWahlLayer[counter] := WahlLayer;
UNTIL (counter>position);

	gName := GetField(5);

	vargName:=concat('(','S=',CHR(39),'*',gName,'*',CHR(39),') & (L IN [',DynWahlLayer[counter],'])');


ForEachObject(SetInfo,vargName);

Link to comment

Maybe you can leave the (L IN [',DynWahlLayer[counter],'])' out of the criteria and see in your SetInfo Procedure if the object is in one of the layers. IF they are, then get the required info of the object.

Something like this:

For counter:=1 TO totalLayers DO

BEGIN

IF GetLayer(h)= DynWahlLayer[counter] THEN

BEGIN

WinH[...]:=h;

Win....

END;

END;

Link to comment

Ok here is the script.

{Maarten Vandickelen and others 2008}
PROCEDURE Layerlist;
VAR
winH : DYNARRAY of HANDLE;
WinL : DYNARRAY of REAL;
WinN : DYNARRAY of STRING;
WinQ : DYNARRAY of LONGINT;
DynWahlLayer : DYNARRAY OF STRING;
total : INTEGER;
count, counter : INTEGER;
tmpS,sytext,gName,vargName : STRING;
tmpCount, posSel, position : INTEGER;
cnt1,cnt2 : INTEGER;
tmpR : REAL;
tmpH, Latemp : HANDLE;
tmpL : LONGINT;
pt1,pt2 : POINT;
ptN1,ptN2 : POINT;
id : LONGINT;
Layerliste : INTEGER;
varLName, WahlLayer : STRING;

{--------------------------------------------------------------------------------------------------}

PROCEDURE Dialog;
VAR
id : INTEGER;
Dialogresult : INTEGER;

		PROCEDURE Define_NameDialog;
		BEGIN
		id := CreateResizableLayout('List',TRUE,'OK','Cancel',TRUE,TRUE);
			{ define the controls for the dialog }
		CreateStaticText(id,4,'Symbolname contains:',-1);
		CreateEditText(id,5,'window',26);

		CreateStaticText(id,6,'Select Layers',-1);
		CreateListBoxN(id,7,33,13,True);

		{ perform the dialog layout }
		SetFirstLayoutItem(id,4);
		SetRightItem(id,4,5,0,0);
		SetBelowItem(id,5,6,0,0);
		SetBelowItem(id,6,7,0,0);

		{ perform final control alignment and adjustment
		AlignItemEdge(id,4,1,1001,0);

		SetEdgeBinding (id,6,FALSE,FALSE,TRUE,FALSE);
		SetEdgeBinding (id,7,TRUE,TRUE,TRUE,TRUE);

		{ create help text for controls }
		SetHelpString(1,'List');
		SetHelpString(2,'Cancel the operation and exit.');
		SetHelpString(4,'Symbolname contains string.');
		SetHelpString(5,'Symbolname contains string.');
		SetHelpString(7,'STRG + click');
		END;

{--------------------------------------------------------------------------------------------------}

		PROCEDURE Drive_NameDialog (Var item,data : LONGINT);
			PROCEDURE Dialogsettings;
				PROCEDURE Layerlistfilling(Layerliste:INTEGER);
				VAR
				I : INTEGER;
				LayerName  : STRING;
				LayerHand : HANDLE;
				id : LONGINT;
				LayerZahl : DYNARRAY OF STRING;

				BEGIN

				ALLOCATE Layerzahl[1..NumLayers];
				LayerHand := FLayer;
				I := 1;

				LayerZahl[i] := GetLName(layerHand);
				REPEAT
						LayerHand := NextObj(LayerHand);
						I := I+1;
						LayerZahl[i] := GetLName(layerHand);
				UNTIL I = NumLayers;

				SortArray(LayerZahl,NumLayers,1);
				FOR I := 1 TO NumLayers DO InsertChoice(7,NumChoices(7),LayerZahl[i]);

			END;

		BEGIN
			Layerlistfilling(Layerliste);
		END;

{--------------------------------------------------------------------------------------------------}

		PROCEDURE SetInfo(h : HANDLE);
			VAR
			cnt : INTEGER;
				bool : BOOLEAN;
			BEGIN
				IF total>0 THEN FOR cnt:=1 TO total DO IF GetSymName(h)=WinN[cnt] THEN
				BEGIN
					bool:=TRUE;
					WinQ[cnt]:=WinQ[cnt]+1;
				END;
				IF NOT bool THEN
				BEGIN
					total:=total+1;
					ALLOCATE winH[1..total];
					ALLOCATE winL[1..total];
					ALLOCATE winN[1..total];
					ALLOCATE winQ[1..total];

					winH[total]:=h;
					GetBBox(h,pt1.x,pt1.y,pt2.x,pt2.y);
					WinL[total]:=pt2.x-pt1.x;
					WinN[total]:=GetSymName(h);
					WinQ[total]:=1;

				END;
			END;

{--------------------------------------------------------------------------------------------------}

PROCEDURE HANDLEOK;
BEGIN


ALLOCATE DynWahlLayer[0..NumLayers];
counter := 0;
posSel := 0;

GetSelChoice(7,posSel,position,WahlLayer);
DynWahlLayer[counter] := WahlLayer;
REPEAT
counter := counter+1;
posSel := posSel+1;
GetSelChoice(7,posSel,position,WahlLayer);
DynWahlLayer[counter] := WahlLayer;
UNTIL (zaehler>position);

	gName := GetField(5);

	vargName:=concat('(','S=',CHR(39),'*',gName,'*',CHR(39),') & (L IN [',DynWahlLayer[zaehler],'])');


ForEachObject(SetInfo,vargName);
IF total<>0 THEN
BEGIN
{create new layer}
	tmpS:='New_Layer';
	IF GetObject(tmpS)<>NIL THEN
	BEGIN
		REPEAT
			tmpCount:=tmpCount+1;
			IF GetObject(ConCat(tmpS,Num2Str(0,tmpCount)))=NIL THEN tmpS:=ConCat(tmpS,Num2Str(0,tmpCount));
		UNTIL(GetObject(tmpS)=NIL);
	END;
	Layer(tmpS);
	SetLScale(ActLayer, 50);
	DoMenuTextByName('Standard Views',1);



{sort symbols by length}
	FOR cnt1:=1 TO total DO
	BEGIN
		FOR cnt2:=1 TO total-cnt1 DO
		BEGIN
			IF WinL[cnt2]>WinL[cnt2+1] THEN
			BEGIN
				tmpH:=WinH[cnt2];
				tmpR:=WinL[cnt2];
				tmpS:=WinN[cnt2];
				WinH[cnt2]:=WinH[cnt2+1];
				WinL[cnt2]:=WinL[cnt2+1];
				WinN[cnt2]:=WinN[cnt2+1];
				WinH[cnt2+1]:=tmpH;
				WinL[cnt2+1]:=tmpR;
				WinN[cnt2+1]:=tmpS;
			END;
		END;
	END;
{place symbol}
	FOR count:=1 TO total DO
	BEGIN
		IF count=1 THEN BEGIN
			Symbol(winN[count],0,0,0);
			GetBBox(LNewObj,pt1.x,pt1.y,pt2.x,pt2.y);
			MoveTo(0,pt2.y-20cm);
			CreateText(Concat(Num2Str(0,WinQ[count]),' St?ck ',CHR(13),WinN[count]));
			SetTextJust(LNewObj,1);
		END ELSE
		BEGIN
			GetBBox(LNewObj,pt1.x,pt1.y,pt2.x,pt2.y);
			Symbol(WinN[count],0,0,0);
			GetBBox(LNewObj,ptN1.x,ptN1.y,ptN2.x,ptN2.y);
		{move this symbol 100cm over the last symbol}
			HMove(LNewObj,pt2.x-ptN1.x+100cm,0);
		{write the quantity and name under the symbol}
			MoveTo(pt2.x-ptN1.x+100cm,ptN2.y-20 cm);
			CreateText(Concat(Num2Str(0,WinQ[count]),' St?ck ',CHR(13),WinN[count]));
			SetTextJust(LNewObj,1);
		END;

	END;

DoMenuTextByName('Standard Views',3);
SetLayerRenderMode(ActLayer,6,true,false);
END;
END;

{--------------------------------------------------------------------------------------------------}

PROCEDURE HANDLEBAD;
BEGIN
END;

BEGIN
	CASE item OF
	SetupDialogC: Dialogsettings;
	1 : HANDLEOK;
	2 : HANDLEBAD;
END;
END;


BEGIN
Define_NameDialog;
IF VerifyLayout(id) THEN
Dialogresult:=RunLayoutDialog(id,Drive_NameDialog);
END;

BEGIN
Dialog;
END;

RUN(Layerlist);

Link to comment

There were a few faults in it. The first was that the Variable zaehler wasn't named under VAR. Also zaehler didn't had any content so therefor you made a loop in the REPEAT...UNTIL (zaehler>position); and you looked in the array with index zero, and that doesn't excist.

An other thing that doesn't work: (L IN [',DynWahlLayer[zaehler],'])... If zaehler would had a content, (for example 2) you would only get the information of the symbols that are on the second selected layer, so all the other layers that you selected would be ignored and that isn't the purpose i asume.

Here's the code again, i just took a few tests, so maybe there are still some faults in it... Only the SetInfo and HANDLEOK Procedures are changed cause the rest seemed OK.

As you can see in the ALLOCATE DynWahlLayer[0..NumLayers]; and FOR laycnt:=1 TO NumLayers lines, the Dynarray gets allocated to wide (the number of layers in the document). I only need the number of selected layers, but i have no idea how you can get that (haven't searched for it either (sorry, little lazy :blush: ) maybe you or somebody else knows the answer?). Anyway, this works too, but would ask (a little) more performance of your computer.

{--------------------------------------------------------------------------------------------------}

		PROCEDURE SetInfo(h : HANDLE);
			VAR
				laycnt : INTEGER;
				cnt : INTEGER;
				bool : BOOLEAN;
			BEGIN
				FOR laycnt:=1 TO NumLayers DO IF GetLName(GetLayer(h))=DynWahlLayer[laycnt] THEN
				BEGIN			
					IF total>0 THEN FOR cnt:=1 TO total DO IF GetSymName(h)=WinN[cnt] THEN
					BEGIN
						bool:=TRUE;
						WinQ[cnt]:=WinQ[cnt]+1;
					END;
					IF NOT bool THEN
					BEGIN
						total:=total+1;
						ALLOCATE winH[1..total];
						ALLOCATE winL[1..total];
						ALLOCATE winN[1..total];
						ALLOCATE winQ[1..total];

						winH[total]:=h;
						GetBBox(h,pt1.x,pt1.y,pt2.x,pt2.y);
						WinL[total]:=pt2.x-pt1.x;
						WinN[total]:=GetSymName(h);
						WinQ[total]:=1;
					END;
				END;
			END;

{--------------------------------------------------------------------------------------------------}

PROCEDURE HANDLEOK;
BEGIN
ALLOCATE DynWahlLayer[0..NumLayers];
counter := 0;
posSel := 0;

GetSelChoice(7,posSel,position,DynWahlLayer[counter]);
REPEAT
	counter := counter+1;
	posSel := posSel+1;
	GetSelChoice(7,posSel,position,DynWahlLayer[counter]);
UNTIL (counter>position);

gName := GetField(5);
vargName:=concat('S=',CHR(39),'*',gName,'*',CHR(39));

ForEachObject(SetInfo,vargName);
IF total<>0 THEN

Link to comment

Dear Maarten,

thank you for your quick reply. There are a few little faults.

"FOR laycnt:=1 TO NumLayers DO" should be

"FOR laycnt:=0 TO NumLayers DO".

But the other fault, i have no idea. The script give always the total quantity of symbols from the first layer in list (regardless if the layer is selected or not) to the last selected layer. any ideas?

Paul

Link to comment

Can you try this one? I'm not sure, but i think this is the problem

PROCEDURE HANDLEOK;
BEGIN
ALLOCATE DynWahlLayer[1..NumLayers];
counter := 1;
posSel := 1;
GetSelChoice(7,posSel,position,DynWahlLayer[counter]);

Because posSel was 0, you also got the first item in the list.

Also, i started the counter (and allocation) at 1 in stead of zero. Otherwise, the REPEAT did one extra loop because UNTIL (counter>position); wasn't correct in this case.

PROCEDURE SetInfo(h : HANDLE);
			VAR
				laycnt : INTEGER;
				cnt : INTEGER;
				bool : BOOLEAN;
			BEGIN
				FOR laycnt:=1 TO NumLayers DO IF GetLName(GetLayer(h))=DynWahlLayer[laycnt] THEN

Again, i'm not completly sure, it's still a little early to think clear :grin: .

Link to comment

Sorry, i made some mistakes:

While debugging i saw that the script only saved the name of the first selected layer. So i was wrong in mine above statement that posSel should be 1... Sorry, you were right!

In the sorting the array part, WinQ wasn't sorted, so you got the wrong quantity with the symbols.

The problem is that the script counts the symbols in all layers not only in the selected ones.

I can't seem to be able to duplicate that same scenario here cause it counted the correct number of symbols (except for the above faults then).

Can you try this code again and see of it works? It works here.

{Maarten Vandickelen and others 2008}
PROCEDURE Layerlist;
VAR
winH : DYNARRAY of HANDLE;
WinL : DYNARRAY of REAL;
WinN : DYNARRAY of STRING;
WinQ : DYNARRAY of LONGINT;
DynWahlLayer : DYNARRAY OF STRING;
total : INTEGER;
count, counter : INTEGER;
tmpS,sytext,gName,vargName : STRING;
tmpCount, posSel, position : INTEGER;
cnt1,cnt2 : INTEGER;
tmpR : REAL;
tmpH, Latemp : HANDLE;
tmpL : LONGINT;
tmpI : INTEGER;
pt1,pt2 : POINT;
ptN1,ptN2 : POINT;
id : LONGINT;
Layerliste : INTEGER;
varLName, WahlLayer : STRING;

{--------------------------------------------------------------------------------------------------}

PROCEDURE Dialog;
VAR
id : INTEGER;
Dialogresult : INTEGER;

		PROCEDURE Define_NameDialog;
		BEGIN
		id := CreateResizableLayout('List',TRUE,'OK','Cancel',TRUE,TRUE);
			{ define the controls for the dialog }
		CreateStaticText(id,4,'Symbolname contains:',-1);
		CreateEditText(id,5,'window',26);

		CreateStaticText(id,6,'Select Layers',-1);
		CreateListBoxN(id,7,33,13,True);

		{ perform the dialog layout }
		SetFirstLayoutItem(id,4);
		SetRightItem(id,4,5,0,0);
		SetBelowItem(id,5,6,0,0);
		SetBelowItem(id,6,7,0,0);

		{ perform final control alignment and adjustment
		AlignItemEdge(id,4,1,1001,0);

		SetEdgeBinding (id,6,FALSE,FALSE,TRUE,FALSE);
		SetEdgeBinding (id,7,TRUE,TRUE,TRUE,TRUE);

		{ create help text for controls }
		SetHelpString(1,'List');
		SetHelpString(2,'Cancel the operation and exit.');
		SetHelpString(4,'Symbolname contains string.');
		SetHelpString(5,'Symbolname contains string.');
		SetHelpString(7,'STRG + click');
		END;

{--------------------------------------------------------------------------------------------------}

		PROCEDURE Drive_NameDialog (Var item,data : LONGINT);
			PROCEDURE Dialogsettings;
				PROCEDURE Layerlistfilling(Layerliste:INTEGER);
				VAR
				I : INTEGER;
				LayerName  : STRING;
				LayerHand : HANDLE;
				id : LONGINT;
				LayerZahl : DYNARRAY OF STRING;

				BEGIN

				ALLOCATE Layerzahl[1..NumLayers];
				LayerHand := FLayer;
				I := 1;

				LayerZahl[i] := GetLName(layerHand);
				REPEAT
						LayerHand := NextObj(LayerHand);
						I := I+1;
						LayerZahl[i] := GetLName(layerHand);
				UNTIL I = NumLayers;

				SortArray(LayerZahl,NumLayers,1);
				FOR I := 1 TO NumLayers DO InsertChoice(7,NumChoices(7),LayerZahl[i]);

			END;

		BEGIN
			Layerlistfilling(Layerliste);
		END;

{--------------------------------------------------------------------------------------------------}

		PROCEDURE SetInfo(h : HANDLE);
			VAR
				laycnt : INTEGER;
				cnt : INTEGER;
				bool : BOOLEAN;
			BEGIN
				FOR laycnt:=1 TO NumLayers DO IF GetLName(GetLayer(h))=DynWahlLayer[laycnt] THEN
				BEGIN			
					IF total>0 THEN FOR cnt:=1 TO total DO IF GetSymName(h)=WinN[cnt] THEN
					BEGIN
						bool:=TRUE;
						WinQ[cnt]:=WinQ[cnt]+1;
					END;
					IF NOT bool THEN
					BEGIN
						total:=total+1;
						ALLOCATE winH[1..total];
						ALLOCATE winL[1..total];
						ALLOCATE winN[1..total];
						ALLOCATE winQ[1..total];

						winH[total]:=h;
						GetBBox(h,pt1.x,pt1.y,pt2.x,pt2.y);
						WinL[total]:=pt2.x-pt1.x;
						WinN[total]:=GetSymName(h);
						WinQ[total]:=1;
					END;
				END;
			END;

{--------------------------------------------------------------------------------------------------}

PROCEDURE HANDLEOK;
BEGIN
ALLOCATE DynWahlLayer[1..NumLayers];
counter := 0;
posSel := 0;

REPEAT
	GetSelChoice(7,posSel,position,DynWahlLayer[counter+1]);
	counter := counter+1;
	posSel := position+1;
UNTIL (counter>posSel);

gName := GetField(5);
vargName:=concat('S=',CHR(39),'*',gName,'*',CHR(39));

ForEachObject(SetInfo,vargName);
IF total<>0 THEN
BEGIN
{create new layer}
	tmpS:='New_Layer';
	IF GetObject(tmpS)<>NIL THEN
	BEGIN
		REPEAT
			tmpCount:=tmpCount+1;
			IF GetObject(ConCat(tmpS,Num2Str(0,tmpCount)))=NIL THEN tmpS:=ConCat(tmpS,Num2Str(0,tmpCount));
		UNTIL(GetObject(tmpS)=NIL);
	END;
	Layer(tmpS);
	SetLScale(ActLayer, 50);
	DoMenuTextByName('Standard Views',1);



{sort symbols by length}
	FOR cnt1:=1 TO total DO
	BEGIN
		FOR cnt2:=1 TO total-cnt1 DO
		BEGIN
			IF WinL[cnt2]>WinL[cnt2+1] THEN
			BEGIN
				tmpH:=WinH[cnt2];
				tmpR:=WinL[cnt2];
				tmpS:=WinN[cnt2];
				tmpI:=WinQ[cnt2];
				WinH[cnt2]:=WinH[cnt2+1];
				WinL[cnt2]:=WinL[cnt2+1];
				WinN[cnt2]:=WinN[cnt2+1];
				WinQ[cnt2]:=WinQ[cnt2+1];
				WinH[cnt2+1]:=tmpH;
				WinL[cnt2+1]:=tmpR;
				WinN[cnt2+1]:=tmpS;
				WinQ[cnt2+1]:=tmpI;
			END;
		END;
	END;
{place symbol}
	FOR count:=1 TO total DO
	BEGIN
		IF count=1 THEN BEGIN
			Symbol(winN[count],0,0,0);
			GetBBox(LNewObj,pt1.x,pt1.y,pt2.x,pt2.y);
			MoveTo(0,pt2.y-20cm);
			CreateText(Concat(Num2Str(0,WinQ[count]),' St?ck ',CHR(13),WinN[count]));
			SetTextJust(LNewObj,1);
		END ELSE
		BEGIN
			GetBBox(LNewObj,pt1.x,pt1.y,pt2.x,pt2.y);
			Symbol(WinN[count],0,0,0);
			GetBBox(LNewObj,ptN1.x,ptN1.y,ptN2.x,ptN2.y);
		{move this symbol 100cm over the last symbol}
			HMove(LNewObj,pt2.x-ptN1.x+100cm,0);
		{write the quantity and name under the symbol}
			MoveTo(pt2.x-ptN1.x+100cm,ptN2.y-20 cm);
			CreateText(Concat(Num2Str(0,WinQ[count]),' St?ck ',CHR(13),WinN[count]));
			SetTextJust(LNewObj,1);
		END;

	END;

DoMenuTextByName('Standard Views',3);
SetLayerRenderMode(ActLayer,6,true,false);
END;
END;

{--------------------------------------------------------------------------------------------------}

PROCEDURE HANDLEBAD;
BEGIN
END;

BEGIN
	CASE item OF
	SetupDialogC: Dialogsettings;
	1 : HANDLEOK;
	2 : HANDLEBAD;
END;
END;


BEGIN
Define_NameDialog;
IF VerifyLayout(id) THEN
Dialogresult:=RunLayoutDialog(id,Drive_NameDialog);
END;

BEGIN
Dialog;
END;

RUN(Layerlist);

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...