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.

What should be a simple macro to scale a solid

Started by samdavo, November 17, 2014, 10:30:33 AM

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

samdavo

Below are two sets of srcipt.
I'm finding something is wrong with the second set.

Background:-
I prefer to leave "Set Handles" with "Any Location" (rather than Centre for instance)
The intent is to select a solid, eg a box, to change set handles to centre temporarily, then to scale the box in x y or z directions.  - ok start with just z direction.
THen to change the "Set Handles" method back to the default of "Any Location".

The first set of script sets the z scaling factor as 1.2 (numerical)
the second asks you to enter the scaling factor.

Problem - I'm finding that the second set gives you a blank screen - maybe what you'd expect if you scaled by zero (??)


Quote
>SetHandle
{
  <Type 1
  }

>RegenerateAll
{
  }

>SelectScale
{
  <Scale 1.0000,1.0000,1.2000
  <Type 0
  }

>SetHandle
{
  <Type 0
  }

Quote'stretch-about-CG.d3m sets the handle of a selection at its centre, then scales it in x and/or y and/or z directions
'then resets the handle preference as "any location" for the next use of Ctrl-H
>SetHandle
{
  <Type 1
  }

input "scale in x,y.and z directions xscale
input "scale in x direction, (press enter to accept default of 1.0)", xscale
if xscale = 0 then
xscale = 1.0
end if

input "scale in y direction, (press enter to accept default of 1.0)", yscale
if yscale = 0 then
yscale = 1.0
end if

input "scale in z direction, (press enter to accept default of 1.0)", zscale
if zscale = 0 then
zscale = 1.0
end if

>SelectScale
  {
  <Scale xscale,yscale,zscale
  <Type 0
  }

'>SetHandle
'{
'  <Type 0
'  }

regen
Clearly I'm doing something wrong.
Any assistance appreciated.

PS furthermore, Zoom to fit Window seems to become unstable - more on that later.

prl

Sam,

Are you looking for the center geometry point of a selection set or the center of gravity of a single solid?  The two could coincide for some solid shapes but it isn't assured. 

And you can't have a CG for multiple solids in a selection set (or not a easy one that I can think of).

DrollTroll

When you use variables in a command's parameter, be sure to enclose them in square brackets -- otherwise they will be treated as zeros.

Specifically, change
  <Scale xscale,yscale,zscale

to
  <Scale [xscale],[yscale],[zscale]

FitToWindow on an object with size zero could indeed be problem-inducing -- what's the scale factor to fit an infinitesimal nothing into a finite space?
25 years with DesignCAD


samdavo

#4
Quote from: prl on November 17, 2014, 11:03:46 AM
Are you looking for the center geometry point of a selection set or the center of gravity of a single solid?  The two could coincide for some solid shapes but it isn't assured. 
prl,
You're right,  CG is a bit ambiguous.  Instead I use "centre", in the same way that set handles uses "centre". 

This macro (tidied up thanks to DT's tip on square brackets) is enclosed, "stretch-about-centre.d3m", and follows on from your macro to subtract the cylindrical centre of extruded "O"'s  from the cylindrical exterior cylinders.
The idea is to stretch the interior to avoid z-fighting.

Here's a previous discussion on the same topic, more typical of what I face - namely z fighting when holes are drilled in plates.   On that occasion, I ALSO didn't find any z-fighting, (as you didn;t with the extruded letter macros);  But I suspect it might come back to bite me ( as Phil warns)
http://forum.designcad.com/index.php?topic=5065.msg32993#msg32993

Back to this macro, it comes between a) and c), viz :-
a) select a hole to be subtracted from a plate
b) (before subtracting it) use the macro to locate its centre and stretch it in the z direction - or any other direction for that matter - indeed in multiple directions if required
c) and THEN subtract it,
this will/should guarantee no z fighting.

Finally it resets  "set handles" as "any location",  rather than "centre". 
cheers.   

PS If you look carefully, the green plate has just a hint of all those extruded shapes to be subtracted (2 cents)

samdavo

#5
Quote from: JJG on November 17, 2014, 12:19:29 PM
Sam, give a look here :
http://forum.designcad.com/index.php?topic=3103.0

JJG - wilco (and I'll get back when I fully understand it) :) thanks and cheers

prl

#6
Quote from: samdavo on November 17, 2014, 05:52:43 PM
Here's a previous discussion on the same topic, more typical of what I face - namely z fighting when holes are drilled in plates.  . . . But I suspect it

Sam, I'll admit right up front I have NOT drilled into reading the various posts so I may be completely off.

I tend to think of z fighting as being a rendering issue, not a solid operations issue.  For rendering, if two surfaces are in essence in the same mathematical plane (think in terms of some sort of coplanar tolerance check), and say the surfaces are indeed mathematically on top of each other,  the rendering programs get confused as to which surface it should "show".


Dr PR

prl,

For Z fighting the two surfaces do not actually have to be coplanar - they can be separated by a distance, say X.

When the image is generated the program puts each image into a "Z buffer: (nothing to do with the drawing's Z axis) that contains cells perpendicular to the line of sight in the image. Each Z buffer cell has a thickness Y (along the line of sight).

If X > Y (the two surfaces are in different Z buffer cells) the nearest surface will display over the more distant surface.

If X = Y or X < Y both surfaces will be in the same Z buffer cell and the images may be blended together or the more distant surface may show on top.

****

I learned this the hard way. I wanted to "paint" one surface on top of another, like real paint. So I created the "paint" surface and placed it very close to the underlying surface - something like 0.025".

When I shaded it with a short View Distance (thin Z buffer cells) it looked OK. But when I put the objects into a larger drawing and shaded with a long View Distance (thick Z buffer cells) the "paint" came out mixed zebra striped with the underlying layer color.

Phil
DesignCAD user since 1987

prl

Quote from: Dr PR on November 18, 2014, 08:32:21 AM
For Z fighting the two surfaces do not actually have to be coplanar - they can be separated by a distance, say X.

I agree.  For any zoom level, the "tolerance" of what the renderer considers coplanar starts getting murky.   From a 1000' feet away, you and I would not be able to tell if two items were in the same plane either.