WhoCanDo Posted May 26, 2022 Share Posted May 26, 2022 Hi, I work in 2D on the Design layers. When I'm given more designs to draw than will fit on an A3 page at a reasonable scale, I will draw them anywhere on the Design layer and then place a rectangle around each design to create a bounding box for each viewport. Then I can sort those viewport crops into an order of my choice and create multiple Sheet layers to accommodate the compete project. The latest project has 34 viewports on 3 Sheet layers when finished. 34 viewports created one at a time is a pain so I have written a macro create all the viewports so I can cut and paste them onto the Sheet layers as I see fit. The problem is that the macro below randomly selects my bounding boxes and makes viewports of the contents, but the bounding boxes it ignores, it just makes a viewport of the whole layer. From the 34 viewports on my current project, it makes 15 viewports from the bounding boxes, and 19 layer viewports. It always uses the same bounding boxes for the 15, and always creates the the same layer viewports. Any ideas as to how to correct this ? procedure Main; var Lyr, LineStyleName : string; i, j : integer; Pt : Array [1..500, 1..500] of real; hL, hV : handle; procedure Log_Selected (h : handle); begin SetName (h, 'Tmp'); i := i + 1; Pt[i, 1] := LeftBoundN (N='Tmp'); Pt[i, 2] := BotBoundN (N='Tmp'); DelName ('Tmp'); end; procedure Create_Viewport; begin hV := PickObject (Pt[j, 1], Pt[j, 2]); if (hV <> Nil) then begin SetSelect (hV); DoMenuTextByName ('Create Viewport', 0); Layer (Lyr); end; end; begin hL := ActLayer; Lyr := GetLName (hL); i := 0; ForEachObject (Log_Selected, ((Sel=True) & (L=Lyr))); DSelectAll; For j := 1 to i do begin Create_Viewport; end; end; run (Main); Quote Link to comment
MullinRJ Posted May 26, 2022 Share Posted May 26, 2022 Hello @WhoCanDo, I did not try to replicate your problem, but I suspect it may have something to do with using PickObject to make your selections. Instead, I built an array of HANDLES to store the crop objects and used the handle array of the crop objects to define the VPs. Here's the sample code: procedure Main; var Lyr : string; i, j : integer; Hands :Array [1..500] of Handle; procedure Log_Selected (h : Handle); begin i := i + 1; Hands[i] := h; end; procedure Create_Viewport(hv :Handle); begin if (hv <> Nil) then begin SetSelect (hv); DoMenuTextByName ('Create Viewport', 0); Layer (Lyr); end; end; BEGIN Lyr := GetLName (ActLayer); i := 0; ForEachObject( Log_Selected, Sel & (L=Lyr) ); DSelectAll; For j := 1 to i do Create_Viewport(Hands[j]); END; Run(Main); It works on a really simple drawing with 5 mock view ports. I get 5 VPs when done. HTH, Raymond 3 Quote Link to comment
WhoCanDo Posted May 26, 2022 Author Share Posted May 26, 2022 Perfect Raymond, your a time saver LOL Quote Link to comment
Baptiste_02 Posted September 19, 2023 Share Posted September 19, 2023 Hi @MullinRJ your code save me a lot of time! I've tried it and it's awesome, but sadly, I would say that after 2 or 3 use and maybe 30 viewports made, vectorworks go crazy. I execute the command, it make the viewport that I want but he keep bringing the "create viewport" settings, I've think it will get stuck on repeat but it end with maybe like 20 or 50 (I've lost the count) more viewport of the whole layer. I think he maybe save the number of previous viewport asked and turn them into whole layer viewport cause he don't have a crop for them. Any idea on how to solve that? 1 Quote Link to comment
MullinRJ Posted September 20, 2023 Share Posted September 20, 2023 Hello @Baptiste_02, After rereading my script, I cannot see anything that would cause what you describe. If you relaunch VW, how many times can you run the script before it starts to misbehave? Perhaps you could upload a file where this problem happens. Others may be able to spot something I didn't, but off the top of my head I don't see anything wrong with the script. Also, you should create a signature showing the version of VW you are using, and your computer specs. This saves people from having to ask, and it may also help someone recognize something relevant to your setup. All the best, Raymond 1 Quote Link to comment
Baptiste_02 Posted September 20, 2023 Share Posted September 20, 2023 Hey @MullinRJ Thank you for your answer and advices for signature, I've copied yours, I'll try to send a personnal vwx file soon (other than from my office eheh). I've tried again this morning and this time I get this error message, maybe it can help to understand if there is something wrong in the code? Quote Link to comment
MullinRJ Posted September 20, 2023 Share Posted September 20, 2023 Do you have more than 500 selected objects? Perhaps you need to create a Dynamic Array to store your handles. It can be as big as 32767 elements. If you need more, then the way the program is written needs to be changed. Add AlrtDialog(concat(NumSelectedObjects)); at the beginning of the script to see how many selected objects you have. Raymond Quote Link to comment
Baptiste_02 Posted September 22, 2023 Share Posted September 22, 2023 So I made a test today where I selected 3 rectangles to creates 3 cropped viewports who have each 13, 19, and 43 objects in. But it create 243 viewports on presentation panel. Quote Link to comment
WhoCanDo Posted October 2, 2023 Author Share Posted October 2, 2023 Since I raised this topic, I've had mostly success, but some anomalies. After fiddling a bit, this is my latest version which of course is specific to my process but may gleam some light on the problem. You must be on the layer of the crop polygons you are using to create the viewports. My line type is probably not available to you so you need to change that to your choice too. procedure Main; Label 1, 2; var Lyr, ViewportLyr, LineStyleName : string; i, j, DashedStyleNumber : integer; Pt : Array [1..500, 1..500] of real; hL, hV : handle; Loop : boolean; procedure Log_Selected (h : handle); var VT : integer; AR : real; hC : handle; begin hC := ConvertToPolygon (h, 0); DelObject (h); SetName (hC, 'Tmp'); i := i + 1; GetPolylineVertex (hC, 1, Pt[i, 1], Pt[i, 2], VT, AR); DelName ('Tmp'); SetDSelect (hC); end; procedure Create_Viewport; begin hV := PickObject (Pt[j, 1], Pt[j, 2]); if (hV <> Nil) then begin SetSelect (hV); DoMenuTextByName ('Create Viewport', 0); if (Loop = True) then begin ViewportLyr := GetLName (ActLayer); Loop := False; end; Layer (Lyr); end; end; begin DelName ('Tmp'); hL := ActLayer; Lyr := GetLName (hL); Loop := True; if (NumSObj (ActLayer) = 0) then Goto 1; if (YNDialog ('Every selection on active layer will be a bounding for a viewport. Continue?') = False) then Goto 2; DashedStyleNumber := -Name2Index('Dash Style-9'); { The bounding polygon will be a line style of choice } LineStyleName := GetDashLineTypeName (DashedStyleNumber); DSelectObj (((V=True) or (V=False)) & (LT <> LineStyleName)); if (NumSObj (ActLayer) = 0) then AlrtDialog ('Crop must be line type Dash Style-9'); i := 0; ForEachObject (Log_Selected, ((Sel = True) & (L = Lyr) & (LT = LineStyleName))); DSelectObj ((V=True) or (V=False)); For j := 1 to i do begin Create_Viewport; end; Layer (ViewportLyr); Goto 2; 1: { Error } AlrtDialog ('No bounding box selected, or bounding box is not "Dash Style-9".'); 2: { Abort }; end; run (Main); Quote Link to comment
Recommended Posts
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.