Jump to content
Developer Wiki and Function Reference Links ×

Can someone help me VS and polys


Recommended Posts

Hi everyone!

This is my first post, I have been this script for several time. Basically this script does is to join a set of Polys consecutively(join poly 1 with 2,3,4,5). The problem now is that I need to modify this script to join the poly 1,3,5.Someone can help me with this please

Thank you in advence

The Script:

Procedure TheProcedure;

{debug}

VAR

x,y,d: REAL;

r, g, b :LONGINT;

h,h1: HANDLE;

s: STRING;

i,j,n,vtx,m,ii,i2: INTEGER;

p1,p2: POINT;

Myp,Myp2: DYNARRAY OF POINT3D;

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

Procedure DrawPol(Myp: DYNARRAY of POINt3D;i:INTEGER);

VAR

h1,h:HANDLE;

j:INTEGER;

BEGIN

layer ('new Lines');

OpenPoly;

BeginPoly;

For j:=1 To i do BEGIN

IF Myp[j].z=0 Then Addpoint(Myp[j].x,Myp[j].y);

IF Myp[j].z=1 Then CurveTo(Myp[j].x,Myp[j].y);

IF Myp[j].z=2 Then CurveThrough(Myp[j].x,Myp[j].y);

END;

EndPoly;

h1:=LNewObj;

ColorIndexToRGB(7, r, g, b);

SetPenFore(h1, r, g, b);

SetFPat(h1,0);

layer(s);

END;

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

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

Procedure Del_Points(Myp: DYNARRAY of POINt3D;i:INTEGER; Dist: REAL; Dist2: REAL; VAR Myp2: DYNARRAY of POINt3D; VAR jj: INTEGER );

VAR

d: REAL;

j: INTEGER;

BEGIN

jj:=1;

FOR j:=1 TO i-1 DO BEGIN

d:= Sqrt (Sqr((Myp[j+1].x-Myp[j].x))+Sqr((Myp[j+1].y-Myp[j].y)));

IF MyP[j].z>0 THEN BEGIN

IF d>dist THEN BEGIN

MyP2[jj]:=MyP[j];

jj:=jj+1;

END;

END

ELSE BEGIN

IF d>dist2 THEN BEGIN

MyP2[jj]:=MyP[j];

jj:=jj+1;

END;

END;

END;

MyP2[jj]:=MyP;

END;

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

Procedure FindP(x,y : REAL;h: HANDLE; VAR ii: INTEGER; VAR xp,yp : REAL);

VAR

x1,x2,y1,y2,dst1,dst2: REAL;

i: INTEGER;

BEGIN

i:=GetVertNum(h);

GetPolylineVertex(h,1,x1,y1,vtx,d);

dst1:= Sqrt( Sqr(x1-x) + sqr(y1-y) );

GetPolylineVertex(h,i,x2,y2,vtx,d);

dst2:= Sqrt( Sqr(x2-x) + sqr(y2-y) );

IF dst1>dst2 THEN BEGIN

xp:=x2;

yp:=y2;

ii:=i;

END;

IF dst1

xp:=x1;

yp:=y1;

ii:=1;

END;

END;

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

BEGIN

h:=ActLayer;

s:=GetLName(h);

n:=NumSObj(h);

h:=FSActLayer;

GetPt(x,y);

ii:=1;

FindP(x,y,h,ii,x,y);

FOR m:=1 TO n DO BEGIN

i:=GetVertNum(h);

ALLOCATE Myp[1..i+1];

ALLOCATE Myp2[1..i+1];

IF ii=1 THEN BEGIN

FOR j:=1 TO i DO BEGIN

GetPolylineVertex(h,j,Myp[j].x,Myp[j].y,Myp[j].z,d);

END;

END;

IF ii=i THEN BEGIN

FOR j:=1 TO i DO BEGIN

GetPolylineVertex(h,i+1-j,Myp[j].x,Myp[j].y,Myp[j].z,d);

END;

END;

h1:=NextSObj(h);

IF h1<>NIL THEN BEGIN

i:=i+1;

FindP(Myp[i-1].x,Myp[i-1].y,h1,ii,Myp.x,Myp.y);

Myp.z:=0;

END;

Del_Points (Myp,i,.2,.2,MyP2,i2);

DrawPol(Myp2,i2);

h:=NextSObj(h);

END;

layer ('new Lines');

END;

RUN (TheProcedure);

Link to comment

Hi Ivan,

I'm not currently some place where I can actually run this script to see it in action, and my knowledge of poly drawing isn't good enuf that I can visualize what you're doing. So a couple of questions:

The script works on a set of selected objects, correct?

Why can't you just select objects 1,3,5 instead of objects 1,2,3,4,5?

Do you still need to join 1,2,3,4,5 but process them in a different order?

"to join a set of Polys consecutively.."

I don't see something that determines the order in which the objects are processed. As written it would seem to be by stacking order...the order in which they are drawn.

It's entirely possible that I'm just missing this part (the ordering), so if it's there please point it out. That's to say how is 'consecutive' determined?

Link to comment

Hi,

thank islandmon and ccroft for reply my question.

ccroft, you are right, I can select objects 1,3,5 and then join them, but the problem is that I work between 700 and 1000 polys. At the moment I am selecting poly 1,3,5 to 700...this job take me around 3 or 4 hours. This is the reason because I want to change the script..select all of them and then only join objects 1,3,5,7..

You can see how it works, drawing a few polys, select all, click "Alternate Line" and click in the right or left side of the polys.

Please let me know if I am clear with this script.

Thank you again for your time

Link to comment

I've never tried this, but if you want to skip every other poly it would seem to be simply a matter of repeating: "handle:=NSObj(handle)".

h:=FSActLayer; gets handle to #1 (in your script)

h1:=NextSObj(h); gets handle to #2 (in your script)

h1:=NextSObj(h1); should get handle to #3 (add to script right after above)

And then towards the end you need to iterate h to #3 handle before going thru the 1st loop again:

replace h:=NextSObj(h); (in your script) with h:=h1;

(The way I read it, "h:=NextSObj(h);" is the same as saying "h:=h1".)

The next time thru the main loop:

h1:=NextSObj(h); gets handle to #4 (in your script)

h1:=NextSObj(h1); should get handle to #5

I still can't test this and there may be something wrong with my thinking. If that's true I'd be happy to have it pointed out, but it seems to me that something along these lines should work.

Link to comment

Ivan,

After reading my post it occured to me that it might be clearer to simply show how I was thinking of changing the script:

IF ii=i THEN BEGIN

FOR j:=1 TO i DO BEGIN

GetPolylineVertex(h,i+1-j,Myp[j].x,Myp[j].y,Myp[j].z,d);

END;

END;

h1:=NextSObj(h);

h1:=NextSObj(h1);???????????????{added to original script}

IF h1<>NIL THEN BEGIN

i:=i+1;

FindP(Myp[i-1].x,Myp[i-1].y,h1,ii,Myp.x,Myp.y);

Myp.z:=0;

END;

Del_Points (Myp,i,.2,.2,MyP2,i2);

DrawPol(Myp2,i2);

h:=h1;??????????????????????????????{change from original}

END;

layer ('new Lines');

END;

And as I said before there's very likely a glaring flaw in my logic...

Link to comment

Sooo.....later that day:

Got to a machine w/ vWorks installed and played with the script. The above seems to work in terms of skipping every other poly. But it fails due to the first FOR loop in the main block.

As written the script counts the number of selected objects and executes the loop that many times. But with the above changes we're skipping objects, so the loop keeps going after the last selected poly has been processed. It gets NIL handles to non-existent objects and spews out faulty data leading to various errors.

The solution seems to be a WHILE loop instead. You can skip the counting part entirely. The loop keeps executing until it gets a NIL handle....IE until it processes the last selected object.

Here's the re-written main block:

BEGIN

h:=FSActLayer;

GetPt(x,y);

ii:=1;

FindP(x,y,h,ii,x,y);

WHILE h<> NIL DO BEGIN????????{was the FOR loop}

i:=GetVertNum(h);

ALLOCATE Myp[1..i+1];

ALLOCATE Myp2[1..i+1];

IF ii=1 THEN BEGIN

FOR j:=1 TO i DO BEGIN

GetPolylineVertex(h,j,Myp[j].x,Myp[j].y,Myp[j].z,d);

END;

END;

IF ii=i THEN BEGIN

FOR j:=1 TO i DO BEGIN

GetPolylineVertex(h,i+1-j,Myp[j].x,Myp[j].y,Myp[j].z,d);

END;

END;

h1:=NextSObj(h);

h1:=NextSObj(h1);

IF h1<>NIL THEN BEGIN

i:=i+1;

FindP(Myp[i-1].x,Myp[i-1].y,h1,ii,Myp.x,Myp.y);

Myp.z:=0;

END;

Del_Points (Myp,i,.2,.2,MyP2,i2);

DrawPol(Myp2,i2);

h:=h1;

END;

layer ('new Lines');

END;

RUN (TheProcedure);

Hope that works for you.

Link to comment

Hi Charles,

Could you help me one more time?

I am working with polygons of 4 colours (red, blue, yellow and green) and the script palette of 4 colours. When I click on the red (in the palette) selects all polygons red, and so in this way with the other colours.

My question is: in the same way that I work with the colours, how I can select the odd polys and the pairs polys using the script pallet?

The function is the same that the other script, but in this case I do not need join them, just select them (odd and pairs)

Script:

Blue: DSelectAll; SelectObj((PF=4));

Red: DSelectAll; SelectObj((PF=7));

Yellow:DSelectAll; SelectObj((PF=5));

Green:DSelectAll; SelectObj((PF=6));

Thank in advance

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