News:

Please note new Forum URL: forum.designcad.com

Main Menu
DesignCAD 3D Max 2027 box
Now available

DesignCAD 2027

Hatches that follow their boundaries, an on-screen dial to turn your model, and a way to find any command by name, in a clean Windows 11 look.

Updated Print Rectangle Macro

Started by bdeck, April 08, 2014, 07:12:06 AM

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

bdeck

Here's an updated Print Rectangle function that uses an external executable to resize a new drawing window to the desired aspect ratio, so that PrintCurrentView can be used to print it.

Just set up printing for "landscape" or "portrait" in advance. No print dialog on this one, but it does manage to print everything in the rectangle (no loss of text, images, and hatches.)

Executable is written in plain vanilla C (Borland 5.5), and uses the MoveWindow function to change the new window dimensions, but does no housekeeping. So don't try to use it in a main drawing window, unless you are ready for trouble. (It might be off by a pixel or two. That doesn't matter in the new window, because it is closed immediately after use. )

This is 2D only, but can be modified for 3D with changes to the rectcheck subroutine and the ar calculation. I dont use 3d, but if anyone wants to tackle that,  please post results.

Note that DesignCad automatically corrects the rectangle to include the width of wide lines when printing. So the rectangle points may be set by snapping to drawing entites, without fear of losing part of a line to clipping.

Heres the macro code.  The executable file and macro are attached.

Please post any bugs or improvements.

bd

EDIT: modified < and > in rectCheck to <= and >= to avoid loss of orthagonal lines on the edge of rectangle
EDIT: v0.3 Added Test for 2d mode. Changed "alert" reference to "message" statement 


'prr.d3m    print rectangle right     v0.3  4/2014   B.Deck

'print rectangle Macro

' copies target rectangle to a new drawing, and scales the window using a called external executable.
' Note that DesignCad automatically corrects for wide line dimensions when printing,
' so rectanlge may be set by sapping to bounding points on dwg without clipping errors.

' Please advise any bugs

threshhold =.005       ' Optional test: dont call executable unless aspect ratio correction exceeds this factor (user selectable)
waitlimit=1000000      ' time limit (in empty loops) for macro to allow external executable to resize window

sys40=sys(40)  'archive cursor style
sys(40)=1  'cursor crosshairs
n=sys(9)                'number of entities
sys(1027)=0 ' set message style
Sys(1) = 0 'erase preset points

If sys(344)=0 then
message "2D mode only"
end
endif

Gosub GetDims   ' center cursor at outset

>SetPoints
{
<MaxPoints 2 ' accepts 3 points in all
<CmdPrompt "Set two points do define a print rectangle "
<Incomplete 1
}

sys(40)=sys40  ' Restore previous cursor

npts = Sys(1)

if npts<2 then
message "2 points not set"
end
endif

Pointval x0,y0,z0,1
Pointval x1,y1,z1,2

if x0>x1 then           'x0 should be smaller than x1 for bounds checking
xtemp=x0
x0=x1
x1=xtemp
endif
if y0>y1 then
ytemp=y0
y0=y1
y1=ytemp
endif
if z0>z1 then
ztemp=z0
z0=z1
z1=ztemp
endif

ar=abs((y1-y0)/(x1-x0))   ' aspect ratio of print rectangle

>Deselect     'deselect any prior selections before selecting items to be copied
{
}

sys(36)=2

gosub rectCheck     'select only those entities sharing viewspace with the print rectangle

''''  anykey          'for diagnostic only

>SetHandle
{
'<Type 0
<Pointxyz 0,0,0
}

>Copy    'Copy the selected entities
{
}
>Deselect
{
}

>New   ' Open new temporary drawing  (DO NOT USE NewWindow{} here)
{
}

>Paste   'put copied entities on new dwg
{
<Type 1          ' 1 = Fixed scale (always paste at original size)
<Pointxyz 0,0,0
}   

>Deselect
{
}

sys$(90)= "Print Rectangle"  'Set title of new window. Exectable must find this String in the window title, or it will do nothing

gosub GetDims

aspectClient=(ny1-ny0)/(nx1-nx0)    'Calculate Starting Aspect Ratio of New Client Window

ARR= ar/aspectClient   'Compare aspect ratio of print rectangle with aspect ratio of New Window
ARRdiff=abs(ARR-1)   'Compare ratio to unity 

if (ARRdiff>threshhold) then
ar$=ar
rstring$="Resizer2.exe " +ar$+chr$(0)
run rstring$,0

For zz=1 to waitlimit    ' wait for executable to change window dimensions (set limit higher if you have a very fast machine)
if (nx1<>sys(601)) then zz=waitlimit
if (ny0<>sys(602)) then zz=waitlimit
next zz

endif

>ZoomWindow   ' make print rectangle fill the new window
{
<Pointxyz [x0,y0,z0]   'addjust these points if necessary to prevent clipping
<pointxyz [x1,y1,z1]   
}

>PrintCurrentView
{
}

>Close    ' close the temporary window
{
<SaveChanges 0
}

sys(36)=0

regen  ' Optional,  ... odd behavior

end

rectCheck:     'select only those entities sharing viewspace with print rectangle (2D Only)

Alias ENT_MINBOUND  &H010F 
Alias ENT_MAXBOUND  &H0110
Alias ENT_SELECTED  &H010C 
Alias ENT_TYPE  &H0101

for i = 1 to n
entity i
Query  ENT_SELECTED, es
if es = 0 then
Query  ENT_MINBOUND, minx, miny, minz
Query  ENT_MAX, maxx, maxy, maxz
if (minx<=x1) and (maxx>=x0) then
if (miny<=y1) and (maxy>=y0) then
Change ENT_SELECTED 1
update
endif
endif
endif
next i
return

GetDims:
nx0=sys(600)   'get window size
nx1=sys(601)
ny0=sys(602)
ny1=sys(603)

>MoveCursor              ' Put cursor in middle of window (optional)
{
<Pointxyz [(nx0+nx1)/2, (ny0+ny1)/2, 0]
}
return





bdeck

#1
After further review,

The page settings (landscape vs portrait)  DC sends to a new window are those active at the previous shutdown of DesignCad.

Changing on the fly between landscape and portrait will require a little more code in the executable  .....
... unless someone knows of a hidden sys() factor for that function... ?

Even a read-only parameter would be useful. Then we could simply rotate the entities in the new window by 90 deg, to change between Landscape and  Portrait printing.

bd

Rob S


Has the need for this macro not been more or less superseded by the new long-awaited Designcad "Print Section" command in V22 and later, which allows you to select any rectangle of the drawing, and then apply the standard print dialog options to it including scale, landscape portrait, etc?




User since forever

bdeck

#3
Hi RobS,

Many thanks for the feedback. My last version was 20.

Planned to order v23, but cant find an upgrade price.

Was not aware that a new "Print Selection" function was ........ (oops need better glasses)

But at least I got my hands dirty with some ugly code.

Best Regards,

BD

DrollTroll

25 years with DesignCAD

bdeck

#5
Thanks DT,

Got v23 downloaded.

This kludge brings up another need.

There is a macro command to open a NewWindow, but apparently no way to resize or close a window in the present drawing. Hence the need to use an external executable in, for example, the 3d View Toggle macro.

Best,

bd