Jump to content

Vectorscript for selecting texts which ones match with worksheet cells


Recommended Posts

I asked AI to write me a script with the function named in the topic.

It gave me this, but it doesn't work. I'm an outsider, what do you think, is it a mess or are there just some small bugs in it?

 

PROCEDURE SelectTextObjects;
VAR
    worksheet : HANDLE;
    num_rows : INTEGER;
    row : INTEGER;
    cell_data : STRING;
    text_objects : ARRAY[1..1000] OF HANDLE;
    i : INTEGER;
BEGIN
    { Get the active worksheet }
    worksheet := GetWSByName('hrsz');

    { Get the number of rows in column A of the worksheet }
    num_rows := GetWSCellNumRows(worksheet, 1);

    { Loop through each row in column A of the worksheet }
    FOR row := 1 TO num_rows DO BEGIN
        { Get the data in the current row of column A }
        cell_data := GetWSCellFormulaN(worksheet, 1, row);

        { Find text objects that match the data in the current row of column A }
        text_objects := FindText(cell_data);

        { Select the text objects that match the data in the current row of column A }
        FOR i := 1 TO Count(text_objects) DO BEGIN
            SetSelect(text_objects[i], TRUE);
        END;
    END;
END;

Run(SelectTextObjects);
 

 

Link to comment

It is a mess.  😞

 

Most of the functions/procedures don't actually exist (GetWSByName, GetWSCellNumRows, FindText) and the ones that do exist are being used incorrectly.

 

Why don't you ask the OI (Online Intelligence:  i.e. this forum) what you are trying to do and you will get much better results.

  • Like 1
Link to comment

I see! In this case could you please help me with this? I have a list of codes (numbers and letters)  in  worksheet cells (only A column). I also have texts on a layer and I want to find the matching ones with my worksheet cells. (these are buliding site ID codes). Of course I could do that each by each with finding text command, but I gave it a try with AI. 

But really, only if it makes fun!

Link to comment

Here is a script that should do what you want.

 

Be careful as it will select text blocks that match the criteria but are not currently visible (hidden layers or classes).

 

By commenting/uncommenting different lines, you can change the behavior of the script from an Exact Match to Begins With to Contains.

Only one line can be uncommented at a time. As written below it does an exact match.

 

Ask if you have more questions.

 

Procedure SelectTextByWorksheetCell;
{©2024  Pat Stanford - pat@coviana.com}
{licensed under the Boost Software License 1.0}
{https://github.com/boostorg/boost/blob/master/LICENSE_1_0.txt}
{TL/DR Use as you want, attribution for source, No warranty}

{This script takes the value of the selected cell in the top visible worksheet (open for editing)}
{and then searches for text blocks in the drawing that have that value.}
{In a file with many text block this could be a very slow operation.}
{The script has three modes that can be set by changing which line is uncommented.}
{Comment a line by placing braces (the characters at the beginning and end of this Line)}
{at the beginning and end of the line. Uncomment a line by removing the braces.}
{Only one of the three lines can be uncommmented at a time.}

{If the first line is uncommented, the script will select items that are an EXACT MATCH}
{for the value in the currently selected worksheet cell.}
{If the secon line is uncommented, the script will select text items that BEGIN with}
{the string in the currently selected worksheet cell.}
{If the third line is uncommented, the script will select items that CONTAIN the string}
{in the currenlty selected worksheet cell.}

{This script can be slighty dangerous as it will select text items that match the Criteria}
{but that are not currenlty visible, including text blocks on other layers or invisible}
{classes. Be careful if you are using this to select items to modify or delete.}


VAR	WSHand, TextHand		:Handle;
	Row1, Col1, N1			:Integer;
	WSString, TextString	:DynArray of Char;
	
Procedure Execute(Hd1:Handle);
	BEGIN
		If GetType(Hd1)=10 THEN
			BEGIN
				TextString:=GetText(Hd1);
				If TextString=WSString THEN  		(*Uncomment this line for exact match *)  
{				If Pos(WSString, TextString)=1 THEN (*Uncomment this line for Begins With *)  }
{				If POS(WSString, TextString)>0 THEN (*Uncomment this line for Contains *)    }
					BEGIN
						SetSelect(Hd1);
					End;
			End;
	End;
	
BEGIN
	DSelectAll;
	WSHand:=GetTopVisibleWS;
	GetWSSelection(WSHand, Row1, Col1, N1, N1, N1, N1, N1, N1);
	GetWSCellStringN(WSHand, Row1, Col1, WSString);
	ForEachObject(Execute, ((T=TEXT)));
End;

Run(SelectTextByWorksheetCell);

 

Select Text By Worksheet Cell.vwx

  • Like 1
Link to comment

Dear @Pat Stanford, I really apprepriate your kindness, and help! Awesome! It Works!

Only one more question: If I undestood your instructions well,  it finds always the matching text for the one selected cell. Would it be maybe possible to ask the script to run trough all the cells and give all the matches to the selection? (Just like I would use the shift button during selecting them manually). Or is this operation not possible?

 

Thank you,

Zsombor

Link to comment

So you would like to select a range of cells in the worksheet and then select all the text items in the drawing that match ANY of those items?

 

It is certainly possible to do this if that is what you want.

 

In the meantime, if you comment out the DSelectAll; line, you could manually do the deselect and then the script would continue to add to the selection when you manually run it on different worksheet cells.

Link to comment

I was going to wait for your response that this is what you want, but my brain insisted on doing this project before any of the other things I am supposed to be doing.  So here is the version that checks and selects text in the drawing that matches any cell in the selected range of the worksheet. It seems to work fine with a single selected cell or selected cells in a column. I have not tested (though I wrote it to handle) a range of multiple columns.

 

Procedure SelectTextByWorksheetCell;
{©2024  Pat Stanford - pat@coviana.com}
{licensed under the Boost Software License 1.0}
{https://github.com/boostorg/boost/blob/master/LICENSE_1_0.txt}
{TL/DR Use as you want, attribution for source, No warranty}

{This script takes the values in the range of selected cells in the top visible worksheet (open for editing)}
{and then searches for text blocks in the drawing that have those values.}
{In a file with many text block this could be a very slow operation.}
{The script has three modes that can be set by changing which line is uncommented.}
{Comment a line by placing braces (the characters at the beginning and end of this Line)}
{at the beginning and end of the line. Uncomment a line by removing the braces.}
{Only one of the three lines can be uncommmented at a time.}

{If the first line is uncommented, the script will select items that are an EXACT MATCH}
{for the value in the currently selected worksheet cell.}
{If the secon line is uncommented, the script will select text items that BEGIN with}
{the string in the currently selected worksheet cell.}
{If the third line is uncommented, the script will select items that CONTAIN the string}
{in the currenlty selected worksheet cell.}

{This script can be slighty dangerous as it will select text items that match the Criteria}
{but that are not currenlty visible, including text blocks on other layers or invisible}
{classes. Be careful if you are using this to select items to modify or delete.}


VAR	WSHand, TextHand										:Handle;
	Row1, Col1, N1											:Integer;
	TopRow, BotRow, LeftCol,RightCol, TopSubRow, BotSubRow	:Integer;
	RowCnt, ColCnt											:Integer;	
	WSString, TextString									:DynArray of Char;
	
Procedure Execute(Hd1:Handle);
	BEGIN
		If GetType(Hd1)=10 THEN
			BEGIN
				TextString:=GetText(Hd1);
				If TextString=WSString THEN  		(*Uncomment this line for exact match *)  
{				If Pos(WSString, TextString)=1 THEN (*Uncomment this line for Begins With *)  }
{				If POS(WSString, TextString)>0 THEN (*Uncomment this line for Contains *)    }
					BEGIN
						SetSelect(Hd1);
					End;
			End;
	End;
	
BEGIN
	DSelectAll;
	WSHand:=GetTopVisibleWS;
	GetWSSelection(WSHand, Row1, Col1, TopRow, LeftCol, TopSubRow, BotRow,RightCol, BotSubRow);
	For RowCnt := TopRow To BotRow DO
		BEGIN
			For ColCnt := LeftCol to RightCol DO
				BEGIN
					GetWSCellStringN(WSHand, RowCnt, ColCnt, WSString);
					ForEachObject(Execute, ((T=TEXT)));
				End;
		End;		
End;

Run(SelectTextByWorksheetCell);

 

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...