Jump to content
Developer Wiki and Function Reference Links ×

Finding a Symbol in a file


hong

Recommended Posts

Somehow this doesn't work.

Could someone take a look?

begin

result:=false;

h:=Fsymdef;

Repeat

SetSelect(h);

If Getsymname(h)='C' Then

Begin AlrtDialog('It is here');

result:=true;

end

ELse h:=nextsymdef(h);

until (h=nil);

If result=false then

AlrtDialog('It is not here');

end;

Link to comment

Hi Hong,

Since you are searching the symbol library for names, use GetName(h) instead of GetSymName(h). The latter is used when you have a handle to a symbol object placed in the drawing. Also, SetSelect(h) is not appropriate here, though it hurts nothing. It is used with handles to objects that are in the drawing to make them selected. I hope this is clear enough.

Raymond

Link to comment

Thank Raymond.

I have revised the script as you recommand, but somehow the alert message doesn't go away when it finds an existing symbol name. Could you continue to help me?

Var

h:handle;

result:Boolean;

begin

result:=true;

h:=Fsymdef;

Repeat

If Getname(h)='C' Then

begin

result:=false;

AlrtDialog('It is here');

end

Else h:=nextsymdef(h);

until (h=nil);

If result then

AlrtDialog('It is not here');

end;

Link to comment

Hi Hong,

You could simply remove the ELSE from your REPEAT loop, or you could simplify the code as follows:

code:

Procedure XXX;

CONST

aSymName = 'aSymbolNameToTestFor';

VAR

h:handle;

result:Boolean;

BEGIN

h := FSymDef;

Repeat

result := (GetName(h) = aSymName);

h:=NextSymDef(h);

until (result or (h=nil));

If result then

AlrtDialog('It is here')

else

AlrtDialog('It is not here');

END;

Run(XXX);
[/code]

The value of Result is set (true or false) inside the repeat loop and does not need to be initialized. The loop will continue until Result is true, or (h = nil). After the loop is done, the proper dialog is displayed.

HTH,

Raymond

Link to comment

Hey Ray

Nifty little tester-looper.Thanks for posting this.I think It's the 3rd or 4th time I've learned something about booleans from you over the years

Are you..... like.....a real programmer or something?

This kind of thinking is hard to come by for the likes of me.

Link to comment

I used to be a real programmer, but then I found out I liked Pascal. If you are not familiar with the reference, see: Real Programmers (the long version) or Real Programmers (Fax humor version).

Unfortunately, I currently work in a vacuum and have no one to copy, so I fear my programming skills are stagnating. Copying and modifying is the best way to learn programming. Also, this board is an invaluable source of info relating to VS.

Feel free to write me anytime off-line with questions and I will gladly help if I can. Do you subscribe to the VectorScript list? If not, go to: http://lists.nemetschek.net/archives/vectorscript-l.html

Raymond

Link to comment

Thanks for the offer and the links.I may take you up on that one day.I've been thinking about a strategy for a project that would replace my current cobbled together collection of scripts.Acutally I've been thinking about it for a year or so.....not quite sure which route to go.My current set-up has it's advantages and disadvantages.

Oh yeah ,I check the v-script list almost daily thru the web interface.I no longer sub-scribe to the mail though.

I've even been so bold as to post once or twice!

See you around

Charles

Link to comment

Raymond;

Can I use this routine to find hatch names in a file, too. Unfortunately though, I don't see any of hatch related script commands such as' Fsymdef' or 'nextsymdef'. Or are they a part of symbols? I say this because they both move between files through resource brower.

Link to comment

Hi Hong,

No, hatch names are not in the symbol definition list.

Use:

FUNCTION NumVectorFills :LONGINT;

and

FUNCTION VectorFillList (index:LONGINT) :STRING ;

as in:

code:

Procedure YYY;

VAR

I, HatchCnt :Integer;

BEGIN

HatchCnt := NumVectorFills;

for I := 1 to HatchCnt do

begin

Message(I, ' - ', VectorFillList(I));

Wait(1);

end;

Sysbeep;

END;

Run(YYY);
[/code]

HTH,

Raymond

Link to comment

Thanks again.

With your help, I made a script to find a specific hatch in a file and create one if not. However, when I applied this routine for a plug-in object, somehow it stop working! I think the command 'NumVectorFills' and 'Vectorfilllist()' are not getting the list or number of Vectorfills in a document. Is this mean that PIO is somewhat independant from a document file?

Link to comment

I'm sorry Hong, any answer I give at this point would be guessing. There are so many things that can keep a script from working. Are you trying to make a VSM PIO? (a menu object?) I will need more description to make an educated guess.

One thing you can try is to put Message() statements at various places in your script to check internal variable values when your script executes. Place the Message() statements one at a time or the last one will quickly overwrite any previous ones. If you need to use several Message() statements at once, you can follow each one with a Wait(1) statement to give yourself enough time to read them.

Good luck,

Raymond

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