Jump to content

losing the handle after clip surface..


joiner

Recommended Posts

Jason,

Getting a handle to a clipped object does work the way you would think it does, although it seems it should.

Here's an example of how it can be done.

Fuge [Wink]

{--------------------- VectorScript ---------------------------}

Procedure ClipObject;

BEGIN

{ * Original Rectangle * }

Rect(2",1",-2",-1");

{* First Rectangle/ Hole *}

Rect(1/4",1/4",-1/4",-1/4");

ClipSurface(PrevSObj(LSActLayer),LSActLayer);

DelObject(LSActLayer);

{* Second Rectangle/ Hole *}

Rect(-3/4",1/4",-1 1/4",-1/4");

ClipSurface(PrevSObj(LSActLayer),LSActLayer);

DelObject(LSActLayer);

{* Third Rectangle/ Hole *}

Rect(3/4",1/4",1 1/4",-1/4");

ClipSurface(PrevSObj(LSActLayer),LSActLayer);

DelObject(LSActLayer);

END;

RUN (ClipObject);

{--------------------- VectorScript ---------------------------}

Link to comment
  • 2 weeks later...

Fuge,

thank you for your time and interest. I should have been more specific with my problem. what i'd like to be able to do is:

PROCEDURE Notcher;

VAR

hl,hr,hn:HANDLE;

BEGIN

Rect(0,2,2,0); {*first rectangle*}

h1:=lnewobj;

Rect(3,2,5,0); {*SECOND rectangle*}

hr:=lnewobj;

Rect(1.5,2,3.5,1.5); {*Clipper*}

hn:=lnewobj;

clipsurface(h1,hn);

clipsurface(hr,hn);

Rect(1.5,1,3.5,0); {*next clipper*}

hn:=lnewobj;

clipsurface(hl,hn);

here depending on which system i use it either crashes all the way out of vectorworks, or ignores the command. the reason i want to do it this way is the above structure works perfectly in 3d using subtractsolid as long as long as the "clippers" are redrawn after subtraction. I was hoping to insert the 2d operations in with the 3d, and be done!! oh well! i'm 80% done with the 2d cutting using a structure that looks a lot like yours.

thanks,

-jason

Link to comment

Jason,

You can get the handle to the new surface with a little finesse. Since it is not obvious where the new object is in the active layer, it is necessary to count the position (N) of the pre-clipped object, and then reassign the handle to the Nth object after clipping.

The procedure KlipSurface, in the modified code below, can be used in place of ClipSurface. For tidiness sake, I also added a boolean to the call to delete the clipping object, if so desired.

It is assumed that H1 points to an object on the active layer for this procedure to work. If H1 points to an object on another layer, or H1 is NIL, it should do nothing. I hope this helps.

Raymond

PROCEDURE Notcher;

VAR

hl, hr, hn :HANDLE;

Procedure KlipSurface(var H1, H2 :Handle; DelTrimObj :Boolean);

{ Clip surface of object pointed to by H1, by object pointed to by H2. }

{ Return a handle to the new surface in H1. If DelTrimObj is true, }

{ then delete the trimming object. }

Var

I, J :Integer;

TmpHnd :Handle;

Begin

{ Find position of handle H1 in the stacking order. }

I := 0;

TmpHnd := LActLayer;

while (TmpHnd<>H1) & (TmpHnd<>nil) do

begin

I := I + 1;

TmpHnd := PrevObj(TmpHnd);

end; { while }

if (TmpHnd<>nil) then

begin

clipsurface(H1, H2);

{ Recover handle H1 }

H1 := LActLayer;

for J := 1 to I do

H1 := PrevObj(H1);

{ Delete trimming object? }

if DelTrimObj then

DelObject(H2);

end; { if (TmpHnd<>nil) }

End; { KlipSurface }

BEGIN

Rect(0, 2, 2, 0); {*first rectangle*}

hl := lnewobj;

Rect(3, 2, 5, 0); {*SECOND rectangle*}

hr := lnewobj;

Rect(1.5, 2, 3.5, 1.5); {*Clipper*}

hn := lnewobj;

KlipSurface(hr, hn, False);

KlipSurface(hl, hn, True);

Rect(1.5, 1, 3.5, 0); {*next clipper*}

hn := lnewobj;

KlipSurface(hl, hn, False);

KlipSurface(hr, hn, True);

END;

Run(Notcher);

Link to comment

For even tighter code, the calling procs can be written like this,

Rect(1.5, 1, 3.5, 0);

KlipSurface(hl, lnewobj, False);

KlipSurface(hr, lnewobj, True);

if procedure KlipSurface is defined like this,

Procedure KlipSurface(var H1 :Handle; H2 :Handle; DelTrimObj :Boolean);

HOWEVER, the first way of defining KlipSurface is safer.

BECAUSE, if procedure KlipSurface (defined the second way) is called with two user defined handle variables AND DelTrimObj is set to TRUE, then the object referenced by H2 gets deleted, and H2 is set to NIL, but the NIL value is not passed back to the calling procedure. So,

Rect(1.5, 1, 3.5, 0);

hn := lnewobj;

KlipSurface(hr, hn, True);

will result in 'hn' being defined incorrectly after the call.

If you are careful in your programming skills, then the shorter code looks and reads better, just be careful of the side effects. Happy New Year.

HTH,

Raymond

Link to comment
  • 1 month later...

To Raymond, Fuge and any other interested party.

upon further review I found that the above procedure does not work in a PIO script, as a "deep" traverse is required to recognize the components of the PIO. I came up with the following which seems to work in all situations.

FUNCTION Clip(ha,hb:HANDLE):HANDLE;

VAR h1:HANDLE;

holder,holder2 :STRING;

PROCEDURE Klip(clipped,clipper:HANDLE);

BEGIN

holder:=GetClass(Clipped);

holder2:=ActiveClass;

SetClass(Clipped,'Temp');

ClipSurface(clipped,clipper);

END;

FUNCTION Recover:HANDLE;

FUNCTION Finder(h:HANDLE):BOOLEAN;

BEGIN

IF GetClass(h)='Temp' THEN h1:=h;

SetClass(h1,'None');

END;

BEGIN

ForEachObjectInLayer(Finder,2,2,0);

setclass(h1,holder);

Recover:=h1;

END;

BEGIN

NameClass('Temp');

Klip(ha,hb);

Clip:=Recover;

DelClass('Temp');

NameClass(holder2);

END;

Thanks for your help, as your ideas lead to the final solution.

-jason

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