Jump to content
Developer Wiki and Function Reference Links ×

Very strange behavior of a script... Can anyone help?


Recommended Posts

I have a script that converts Polygons in a custom object named 'db Allesstempel'.

The workflow is: you select one or more polygons, you call the script via menu command, and boom: the script converts the polygons to this custom path object named 'db Allesstempel'.

The problem is:

It worked fine for a long time but since one of the last VW Updates it does not work within annotations of viewports if I want to use it on MORE than ONE selected polygon.

It stops with this error: error on line...

SObjectHandle[zaehl] := objectH;

... ZAEHL - index outside array limits:

Why does this happen? There is a function "H_FSActContainer", that checks what's selected. This worked fine for a long time, even within annotations. Now there seems to be a problem. Can anybody help?

Kind regards

VvierA

--------------------------------------

PROCEDURE allesstempelkonverter;

VAR

objectH, newobjH :HANDLE;

SObjectHandle :DYNARRAY [] OF HANDLE;

numsel, zaehl :INTEGER;

FUNCTION H_ActContainer: HANDLE;

BEGIN BeginContext;

Locus(0, 0);

H_ActContainer := GetParent(LNewObj);

DelObject(LNewObj);

EndContext(0);

END;

FUNCTION H_FSActContainer: HANDLE;

VAR h : HANDLE;

BEGIN h := FIn3D(H_ActContainer);

WHILE (h <> NIL) & (Selected(h) = FALSE) DO

IF Selected(h) THEN

H_FSActContainer := h

ELSE

h := NextObj(h);

H_FSActContainer := h;

END;

BEGIN

objectH := H_FSActContainer;

numsel := Count((SEL=TRUE));

ALLOCATE SObjectHandle[1..numsel];

zaehl := 1;

WHILE (objectH <> NIL) DO BEGIN

SObjectHandle[zaehl] := objectH;

zaehl := zaehl+1;

objectH := NextSObj(objectH);

END;

{message (numsel,' Zähler ',zaehl);}

{in der zweiten Schleife werden die Objekte umgewandelt}

zaehl := 1;

WHILE zaehl <= numsel DO BEGIN

IF (GetType(SObjectHandle[zaehl]) = 3) OR {Prüfung ob es ein Rectangle ist}

(GetType(SObjectHandle[zaehl]) = 4) OR {Oval}

(GetType(SObjectHandle[zaehl]) = 5) OR {Polygon}

(GetType(SObjectHandle[zaehl]) = 6) OR {Bogen bzw. Kreis}

(GetType(SObjectHandle[zaehl]) = 21) THEN BEGIN {Polyline}

{ SetPenFore(SObjectHandle[zaehl],45);}

newobjH := CreateCustomObjectPath('db Allesstempel', SObjectHandle[zaehl], nil);

END;

zaehl := zaehl+1;

END;

END;

run(allesstempelkonverter);

Link to comment

This is a common error when you try to acces an array item that's not there.

numsel := Count((SEL=TRUE));
ALLOCATE SObjectHandle[1..numsel];
zaehl := 1; 

WHILE (objectH <> NIL) DO BEGIN

SObjectHandle[zaehl] := objectH;
zaehl := zaehl+1;
objectH := NextSObj(objectH);

END;

Notice that you define your counter "zaehl " as 1, without checking there is atleast one object selected.

You try to acces SObjectHandle[1] in a situation where it's not declared (numsel being 0).

I've also had some weird behavior with dynamic arrays in the past, where I had to declare them size+1 to work in some special cases but I don't think that's the issue now.

Link to comment

Thank you very much for the hints, Hippocode.

Unfortunately I couldn't solve the problem yet though.

numsel := Count((SEL=TRUE));
ALLOCATE SObjectHandle[1..numsel];
zaehl := 1; 

WHILE (objectH <> NIL) DO BEGIN

SObjectHandle[zaehl] := objectH;
zaehl := zaehl+1;
objectH := NextSObj(objectH);

END;

Notice that you define your counter "zaehl " as 1, without checking there is atleast one object selected.

Strangely there is no problem, if I select one object. The error happens only if I select more than one.

You try to acces SObjectHandle[1] in a situation where it's not declared (numsel being 0).

I thought that with "numsel := Count((SEL=TRUE));" I make sure, that numsel is at least 1. There is no error message if I do not select anything and call the script.

Link to comment

Carl,

   Try this instead of your function:

FUNCTION H_FSActContainer: HANDLE;
VAR 
h : HANDLE;
BEGIN 
h := FIn3D(H_ActContainer);
if not Selected(h) THEN
	h := NextSObj(h);
H_FSActContainer := h;
END;

   It may not solve all your problems, but it will return the First Selected Object inside your container. I did not execute your code. I just noticed your WHILE loop would not stop at the first Selected object. This function will return NIL if no objects are selected.

HTH,

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