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.

A Segment Process for Loop Type Structures

Started by ablincoe, March 31, 2014, 11:37:46 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ablincoe

As I have noted in the past, my CAD drawing style has not settled down, and getting surfaces to flow nicely has been one of my major issues.  Based on Dr PR's article, I decided to try and straighten out some loop type structures which were made up of Arc's combined with Curves, and Mirrored to form the other half.  To get these straightened out, I used a combination of manual and automated processes. 
     I Set a PointMark  at a good place to control my divisions
     I combined all of the sub-components of my loops (Arc's, Curves, Lines, etc.) into a single Line entity  (B)
     I Selected my PointMark  (and found that it does matter how close to the center of your PointMark display the selection point lands)
     I ran the below macro to do the divisions, display the points created (Array does not always process in the same direction every time)
          There is an input to confirm the Start and Direction to process the points which can be used to re-order how the Array built them
               The normal entries are  "1 1"  (start at point 1 and increment at +1 to the next one), or "1 -1" (start at point 1 and go the other direction)
                    You can start at any of the points (as numbered) and go in either direction, so your "Array Start" does not have to be your "Curve/Vector Start"

I did use a number of "PRL"s concepts as well as other comments from the forum to come up with this one.

Allen

'  Program:  SegitLoop.d3m  (DesignCAD Macro)
'  Purpose:  Segment and re-draw an Entity (or combined group of entities)
' The process expects the entity to be a complete loop only
' I have utilized "PRL's" "LineSnap" enhancement in this
'  Usage:
' 1)  Create a Draw/"PointMark" where you want the process to begin
' 2)  Manually Select and COMBINE  the entities into a single line  (B)
' 3)  Select the PointMark
' 4)  Run the Macro
' If you don't like how the points are distributed, you can "END"
'    at the confirmation of Start/Direction, "UnDo" the array points
'    and then re-start the macro with a different number of segments.
' LINE_SNAP  seems to be impacted by what "view" you are in ! ! !
'     Make sure your current view has the lines as broadly spaced
'     as possible
'  SUB-ROUTINES Utilized
' SPLIT_WHITE To handle parsing of one of the inputs
'  Author:  ablincoe  -  Allen Blincoe
'

DIM SPLIT$(100) '  For - SPLIT_WHITE
DIM PX(2000), PY(2000), PZ(2000)
SYS(1027) = 1 '  SET Message Boxes to OK/Cancl
MAX_ENT  = SYS(9) '  HIGHEST Entity ID
OPEN "O", 2, "SegitLoop.log"

E_ID = 0
IF SYS(80) = 1  THEN '  SOMETHING Selected  ?
    GetSelect  1, E_ID '    YES - Find out what
    ENTITY E_ID
    IF SYS(90) <> 70  THEN '    Is it a - PointMark ? ?
      Message "ONLY 1 entity (PointMark) can be selected" '    NO
      GoTo THE_END ' B_A_I_L
      END IF
   ELSE '    NOTHING SELECTED
    Message "Nothing has been selected.  Select and re-star the MACRO"
    GoTo THE_END ' B_A_I_L
    END IF

LAYDEST = -1
DO WHILE  LAYDEST < 0  OR  LAYDEST > 2000
    INPUT "Destination Layer  (0=current):  ", LAYDEST
    IF SYS(999) = 1  THEN GoTo  THE_END
    LOOP
NDIV = -1
DO WHILE  NDIV < 3  OR  NDIV > 999
    INPUT "Number of Segments (3 -> 999): ", NDIV
    IF SYS(999) = 1  THEN GoTo  THE_END
    LOOP
L_OUT$ = ""
DO WHILE  L_OUT$ <> "C"  AND L_OUT$ <> "c"  AND _
L_OUT$ <> "L"  AND  L_OUT$ <> "l"
    INPUT "Type of Output ((L)ine, (C)urve): ", L_OUT$
    IF SYS(999) = 1  THEN GoTo  THE_END
    LOOP

PointVAL X, Y, Z, 1 '  Get the PointMark spot
>ARRAY '  Goes CLOCKWISE on "Side" view
{
  <NCopy [NDIV, 1, 1] ' Number of Copies
  <AlongCurve 1
  <PointXYZ [X, Y, Z] ' Point of PointMark
}
' '  THE ABOVE  -  adds  "NDIV"
' '    Entities to the drawing
' '    They are sequentially #'d
' '
WINDOW  (NDIV * 1.5), 60
print  "ARRAY Points as calculated"
print #2,  "ARRAY Points as calculated"
for i = 1 to NDIV
  ENTITY  (MAX_ENT + i)
  PointVAL PX(1000 + i), PY(1000 + i), PZ(1000 + i), 1
  print  i, PX(1000 + i), PY(1000 + i), PZ(1000 + i)
  print #2,  i, PX(1000 + i), PY(1000 + i), PZ(1000 + i)
  NEXT i

print "NEXT INPUT  -  is actually START point and DIRECTION"
INPUT "Confirm Start and Direction (1 1): ", A$
  IF SYS(999) = 1  THEN GoTo  THE_END
  IF A$ <> ""  THEN GoSub SPLIT_WHITE '  IF a Response, go get it
  IF A$ = "" THEN '  IF NO Response, set Defaults
SPLIT$(1) = 1 '    DEFAULTs
SPLIT$(2) = 1
END IF
  S = SPLIT$(1) '  OUTPUT STARTING POINT
  D = SPLIT$(2) '  POINT PLOTTING DIRECTION
  print #2, "Sequence: ", A$
  for i = 1 to NDIV '    Normally  1 or -1
PX(i) = PX(1000 + S) '  NEXT OUTPUT POINT into ARRAY
PY(i) = PY(1000 + S)
PZ(i) = PZ(1000 + S)
print #2, i, S, PX(i), PY(i), PZ(i)
S = S + D '    DIRECTION/STEP
IF S < 1  THEN S = S + NDIV '      Got TOO Low ....  FIX
IF S > NDIV  THEN S = S - NDIV '      Got TOO High ...  FIX
NEXT I '    LOOP to end of points

  print #2, "Plotting:"
  IF L_OUT$ = "C"  OR  L_OUT$ = "c"  THEN '  OUTPUT to a CURVE  ?
    >CURVE ' YES
     {
      IF LAYDEST <> 0  THEN
<LAYER [LAYDEST] '    The CHOSEN Layer
END IF
      <TYPE 0 '    Insure it stays a curve
      for i = 1 to NDIV '    FOR - EACH - Point
<LineSnap [PX(i), PY(i), PZ(i)] ' SNAP it to the original
print #2, i, PX(i), PY(i), PZ(i)
NEXT i
      <LineSnap [PX(1), PY(1), PZ(1)] ' Return to the start
print #2, i, PX(i), PY(i), PZ(i)
     }
    ELSE '  OUTPUT to a LINE (Vector)
    >LINE
     {
      IF LAYDEST <> 0  THEN
<LAYER [LAYDEST] '    The CHOSEN Layer
END IF
      for i = 1 to Npoints '    FOR - EACH - Point
<LineSnap [PX(i), PY(i), PZ(i)] ' SNAP it to the original
print #2, i, PX(i), PY(i), PZ(i)
NEXT i
      <LineSnap [PX(1), PY(1), PZ(1)] ' Returning to the start
print #2, i, PX(i), PY(i), PZ(i)
     }
     END IF

A$ = ""
DO WHILE  A$ = ""
  INPUT "Erase all related  -  PointMark(s)  (Y/N):  ", A$
  IF SYS(999) = 1  THEN GoTo  THE_END
  IF  A$ <> "Y"  AND  A$ <> "y"  AND  _ '    CORRECT Response  ? ?
A$ <> "N"  AND A$ <> "n"  THEN ' (Yy/Nn)
    A$ = "" ' NOpe, CLEAR response
    END IF ' To ASK AGAIN
  LOOP
IF A$ = "Y"  OR  A$ = "y"  THEN '    ERASE the PonitMark(s)
  >ERASE '    YES - ERASE initial one
   { ' Bumps ARRAY down to
   } ' MAX_ENtart point
  FOR i = 1 to NDIV '    FOR EACH ARRAY COPY
    GetAttr  MAX_ENT, E_TP, E_SEL ' GET the Attribute
    IF E_TP = 70  THEN ' INSURE it is a PointMark
      PutAttr  MAX_ENT, E_TP, 1 ' Set to Selected
      >ERASE ' ERASE it
       {
       }
      END IF
    NEXT i
  END IF

THE_END:
END

'  = = = = = = = = = = = =  SUB-ROUTINES  = = = = = = = = = = = = = = = = =

SPLIT_WHITE: '  A WHITE SPASE PARSER
  FOR M_IDX = 1 to 100 '  CLEAR DESTINATIONs
    SPLIT$(M_IDX) = "" '   One at a time
    NEXT I
  M_IDX = 1 '  Where to start within  -  A$
  M_L   = LEN(A$) '  Where must I stop
  M_VAR = 1 '  Index for Array Offset

  M_CH$ = ""
  DO WHILE  M_IDX <= M_L '  START THE PARSING
    M_CH$ = MID$(A$,M_IDX,1) '    My (next) Character
    IF  SPLIT$(M_VAR) <> ""  AND  _ '  TIME for the NEXT entry ?
      M_CH$ <= " "  THEN
      M_VAR = M_VAR + 1 '    INCREMENT Index Pointer
      IF M_VAR = 100  THEN '    LAST VARIABLE available
SPLIT$(M_VAR) = MID$(A$,M_IDX,9999) '   SAVE THE REST here
M_CH$ = " " '   Clear CHAR Buffer
M_IDX = M_L '   Set END OF INPUT
END IF
      END IF
    IF  M_CH$ > " "  THEN '  A character needs saving
      SPLIT$(M_VAR) = SPLIT$(M_VAR) + M_CH$ '    SAVE the character at IDX
      END IF
    M_IDX = M_IDX + 1 '    Move on down the string
    M_CH$ = ""
    LOOP
RETURN

prl

Way to go!!!  I'm glad you found DesignCAD and BasicCAD.