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.

Super-regen macro

Started by samdavo, March 25, 2013, 02:40:14 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

samdavo

Might as well place this macro on the record.

You should run it if "fit to window" - pressed repeatedly - causes a line to toggle on and off randomly.

It simply selects all,
duplicates it in the same spot
and deletes the original.
Think of it as a "super-regeneration".

It should end with everything selected - this indicates the macro ran to end;

As a check, when finished, check if "fit the window" still causes those lines to toggle on and off.

It evolved whilst investigating the cures for another thread with "weird printing effects"
http://forum.designcad.com/index.php?topic=4854.15
(2 cents).

Feel free to critically review it, and/or improve it.

paulerens

#1
Hi samdavo,
I think that all this is not necessary if you use <FitToWindow>
I use in my macros (if possible), FitToWindow after extra-silent mode Sys (36)=2, Instead of <Regen> and I think the result is faster and better.


samdavo

Paul,
It's more complex that that.
And it could be an extremey rare problem.  But, if it happens, then this is a cure  ...

Herewith a couple of drawings (very similar except for a slight shift of the grey matter).
Firstly check out pressnig "fit to window" several times.

If you run that "super-regen" macro on each, and press "fit to windwo" some more, you will find that the black zigzag line appears (consistently) and also prints - where it didn't before. 

The other macro that fixes it is DT's DeleteTinySegments.  However, I found that there were some potential unwanted side effects - all as xeplained on the other thread ( weird printing problem).
cheers
sam

paulerens

#3
Sam,
Very strange effect.
The black line (scale 2 width 0.4) is sometimes visible and sometimes not, in version 21.

I have  opened your drawing in version 22.1.
There is not this strange behavior, as sometimes visible and sometimes not.
Paul,

Dempsey

The disappearing line contains 13 points. Visually I counted 11 points. So, I broke the line and re-combined the individually visible lines. The g-to-m line has two selectable pieces. I combined the lines, set the line width to 0.4 again, and I can now do fit-to-screen without any failure.
Dempsey

samdavo

#5
Paul
I still have this effect with V22.

Dempsey
The problem is two identical points at e (the 5th and 6th).
PS I twigged to this way to fix it (using N-duplicate) after reading your post on that thread.  (PS Oops - it was Rob S's post, sorry)/

PS Damned if I know what causes it though.  It is possible to use "move-a-point" (ie. with asterisk  *) and end up with multiple such effects of two points at an apex.  But I don't think that fully explains the problem here. 
cheers

paulerens

#6
Sam,
The file opens  for me in Version 21.2.
There after I did copy and past, to test the file, in to version 22.1!
So, perhaps the file is cured by this operation.(new entity number)

Dempsey,
Breaking the line and then join together, creates an new entity number, just like making a copy.

Paul

samdavo

#7
Paul
Thanks for that double checking.  As I said above, I have not been successful in working out how that line was formed in the first place (J-wetzel might know ?)

Incidentally (if you are interested in weird effects)... -
starting with 1b stripped.dcd, 
Copy and paste the black line more than once.  (NB use cntl+C, and cntl+V, do not use N-duplicate).
Press fit to window a few times - you will probably get several of them toggling on and off (but it will depend on zooming, and also whether it is reloaded etc).  Check if they print (somewhat random).

Now for some of the problems I have with DeleteTinySegments - at least with this example of a "zero" segment (not just tiny)...
Starting again with 1b stripped.dcd,
select all (Cntl+A)
run DTS
the line disappears entirely.

Starting yet again with 1b stripped.dcd,
note that the black line is in layer 1
set current layer as 2, and lock layer 1
run DeleteTinySegments
then press Fit To Window.
See if you get what I get, namely a spike in the outline to the southwest  (- see attached jpeg,  screendump zoomed in).

Other strange effects occur if you have all selected with multiple lines - and you run DTS - you truncate some of the lines by a segment or two.

Anyway, fwiw, super-regen seems to avoid these problems. 

paulerens

#8
Sam,
After examining the severals files, I find that all line entities consist of 13 points and 12 corners or endpoints.
So, there must be points on the same place.
Except the last file(1b stripped after DTS) has no double points (has 13 points but point (f) Is located at a distance of + - 90000 units!!!)

Therefore, below a macro to destroy the double points .
Select a line and run the macro.
Paul.

'=============================
'Macro to erase double points
'=============================
If Sys(242) = 0 Then
Sys(242) = 1
End If
Sys(36)=2
Sys(49)=1
Sys(48)=0
mineen = 0
GetSelect 1,K
Entity K
lt =Sys(91)
lts =Sys(97)
ltt =Sys(98)
lastpt=Sys(1)
pointval x1, y1, z1, 1
pointval x2, y2, z2, lastpt
dis = Sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) + (z2-z1)*(z2-z1))
If dis < 1e-6 Then
mineen = 0
End If
count=sys(1)
Dim x(count)
Dim y(count)
Dim z(count)
Getattr K, type, select, laynum, group, red, green, blue
lay = laynum
ty = type
rood=red
groen=green
blauw=blue
Putattr K, type, select, laynum, group, red, green, blue

count=sys(1)
    for L = 1 to count
      Pointval x(L), y(L), z(L), L
next L
>Erase
{
}
>Line
{
<Layer [lay]
<lineStyle [lt,lts,ltt]
<Color [rood ,groen ,blauw]
for L = 1 to count
dist = Sqrt((x(L-1)-x(L))* (x(L-1)-x(L)) + ((y(L-1)-y(L))* (y(L-1)-y(L))))
If L > 1 Then
If dist < 0.01 Then
Goto over
End If
If dist > 50000 Then
Goto over
End If
End If
af = 0
dist = 0
<Pointxyz [x(L), y(L), z(L), L]
over:
af = af + dist
Next L
}
GetSelect 1,K
Entity K

las=Sys(1)
dif = lastpt - las
If dif > 0 Then
Message,dif,"Double points found and deleted."
Else
Message "No double points found."
End If
Sys(80)=0
Sys(49)=0
Sys(48)=1
Sys(36)=0
>FitToWindow
{
}
End

Dr PR

It is perfectly "legal" to have two points at one location. In fact, this is a feature of curved lines (C) where you want to add a "kink" or sharp corner in an otherwise smooth curve. It is handy for drawing ship hull cross sections with a sharp corner where a "knuckle" exists on the hull.

However, it is very difficult to control the knuckle location if you use curves with two points at the same location with the "Surface Connect" function. It is better to break the curve at the double point location and generate two different surfaces on either side of the knuckle.

I have found that you may get odd effects if you try to hatch fill a line with two points at one location.

Also, if a line with two points at one location is edited all bets are off about point numbering.

I have seen the effect where a point somehow gets positioned far, far away from the rest of the drawing, but I don't know if this has something to do with multiple points at the same place.

Phil
DesignCAD user since 1987

paulerens

Phil,

The problem is the use of two points at one location  in width lines.

DrollTroll

DeleteTinySegments moves duplicate points in entities to a specific location, then selects and deletes just those points. I wanted to be able to edit the original entities directly instead of making copies. I suppose if some problem entities are on a hidden or locked layer it might have trouble deleting those moved points. Even Trolls can't always think of everything.
25 years with DesignCAD

samdavo

#12
Thanks Paul and Phil,
all helps with the background understanding.

DT, you have a line in your macro DTS (reply #7 of DT's Toolbox), which has an apostrophe.
Deleting the (') might help at least one of the effects I found.  I was just using it as I found it:-

'clear the selection set
'Sys(80) = 0

PS Clearly your macro works for small as well as zero segments (once you twig it as above),
whereas mine probably only works for zero segment effects (and possibly weird ones at that).

As for the concept of care with tiny segments, poorly conditioned equations are bound to give strange effects, clearly what you have been getting at.

No criticism meant, just that the (current) DTS macro needs some twigging and/or warning about
a) not having anything selected, and
b) all layers unlocked. 
(imho)
cheers   

DrollTroll

#13
Actually, I think there's a more serious bug; if I delete a 2-point line that has no length, it messes up the subsequent entity ids and I don't account for that in my macro! I'll have to do some fixin' there. I think reversing the order by which entities are inspected in the first For loop should do it.

*edit* Updated DeleteTinySegments posted. Fixes Sys(80), problems with locked layers, and erasure problems.
25 years with DesignCAD

samdavo

If anyone is good at explaining macros to amateurs,
and has absolutely nothing to do over Easter,
could they please explain to me why my macro (first post) leaves eveything selected (?)

I say (glibly) that it ends with eveything selected, "which indicates it went to fruition",  but to be honest I can't understand WHY. lol.
I thought, having deleted the first selection, it would be left with nothing selected (??!)
PS I run DCAD with "select object when created" turned off.
cheers.
sam