Author Topic: Question regarding a continuation ...  (Read 4736 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Swamp Rat
  • Posts: 566
Question regarding a continuation ...
« on: March 15, 2007, 12:09:05 PM »
Hello everyone.  I have finally got a piece of code put together that you all have helped me on that I would like to share with you.  It's not quite finished yet, there are some things I still have to add & tweak, but it is working.  If you have the time, I would love to have some feedback / advice on my code.
The first code, UpdateTypDetails creates a script which calls the second code, TypDtlUpdate.
See the attached files.

There were several discussions about different topics of this same code, you can find them here.
Quote
Script search for drawings ...
http://www.theswamp.org/index.php?topic=15024.0

CHPROP Problem ...
http://www.theswamp.org/index.php?topic=15200.0

Changing Dim styles
http://www.theswamp.org/index.php?topic=15183.0
Just in case you were really bored and wanted to follow along.  :D

Anyway, here is one minor little piece I still need some help on.
There are two files; UpdateTypDetails which creates a script for several drawings.
The second file, TypDtlUpdate runs the update for the details.
Some of the details I am updating error out on one thing or another.
I would like to list these drawings that the routine is erroring out on in a txt document and have the program continue its update with the other drawings in the script.
Unfortunately, I can't seem to get this thing to keep the program running.
Here's what I have.
Code: [Select]
  (defun $error (msg /)
    (if (or (= msg "Function cancelled") (/= msg "quit / exit abort"))
      (princ (strcat "Error: " msg)))
    (setq ErrorPath (getvar "dwgprefix"))
    (setq ErrorDwg (getvar "dwgname"))
    (setq ErrorLog (strcat ErrorPath ErrorDwg "-Error.log"))
    (setq ErrorFile (open ErrorLog "W"))
    (write-line (strcat (getvar "dwgname") " - Error: " msg) ErrorFile)
    (close ErrorFile)  ;;;  [color=blue]Doht, I've gotta figure out how to append to the next line rather than over write the first too.[/color]
    (command ".undo" "e" "undo" "B")
    (command ".redraw")
    (setvar "cmdecho" 1)
    (setvar "filedia" 1)
    (setvar "clayer" "0")
    (setvar "expert" 0)
    (setq *error* old_err
          oldecho nil
          oldos nil)
    (command ".qsave")
    (princ)
  ); End $error
So, if there is an error, it needs to write the name of the drawing to the txt file, undo everything back to a mark, save the drawing, close it,
AND allow the script to run on the next drawing in line.

Does anyone know how I can make this happen ??
Thank you.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

JohnK

  • Administrator
  • Seagull
  • Posts: 10651
Re: Question regarding a continuation ...
« Reply #1 on: March 15, 2007, 01:31:12 PM »
I think i follow you; Do we know conditions that might cause errors?

Pertaining to your writing to next line question, you need to open the file to APPEND not write.  ... ``(open ErrorLog "a")''
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Hangman

  • Swamp Rat
  • Posts: 566
Re: Question regarding a continuation ...
« Reply #2 on: March 15, 2007, 02:05:21 PM »
I think i follow you; Do we know conditions that might cause errors?
Well, there are a few different ones from the batch I've tested.  Little things like "cannot create Dimblk = "" ".
I've still gotta tinker a bit with these and figure out what I can do.
The one's that are really bugging me don't have any listing, it just simply stops.  I've tried tracing it, and the program seems to go through completely, but after the qsave at the end, it just stops.  ???  Sometimes I can get through about 5 drawings, sometimes just 2, then it just stops.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

JohnK

  • Administrator
  • Seagull
  • Posts: 10651
Re: Question regarding a continuation ...
« Reply #3 on: March 15, 2007, 02:57:28 PM »
Have you read my ``Methods'' document?

TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Hangman

  • Swamp Rat
  • Posts: 566
Re: Question regarding a continuation ...
« Reply #4 on: March 15, 2007, 03:39:35 PM »
Have you read my ``Methods'' document?



Uuuummmm, ...  NO !!

where do I find it ??
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

JohnK

  • Administrator
  • Seagull
  • Posts: 10651
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10651
Re: Question regarding a continuation ...
« Reply #6 on: March 15, 2007, 05:42:04 PM »
First thing I would like to clean up is your layer-search-multiple-if-thing you've got going on in the TypDtlUpdate proced.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Hangman

  • Swamp Rat
  • Posts: 566
Re: Question regarding a continuation ...
« Reply #7 on: March 16, 2007, 10:24:05 AM »
First thing I would like to clean up is your layer-search-multiple-if-thing you've got going on in the TypDtlUpdate proced.


You mean this ??
Code: [Select]
    (if (tblsearch "layer" "ARCH")
      (progn
        (if (not (tblsearch "layer" "S-Arch")); if S-Arch does not exist, create it
          (command ".-layer" "New" "S-Arch" "Color" "15" "S-Arch" ""))
        (setq LayerArch (ssget "X" '((8 . "ARCH")(67 . 0)))); Get everything on Layer (8) ARCH in MS only (67.0)
        (if (/= LayerArch nil)
          (command ".CHPROP" LayerArch "" "LAyer" "S-Arch" "")))); Change everything selected to new layer

How would you clean it up ??
Thinking more into this, it would probably be a bit better in a conditional statement rather than the if statements.  But conditional only runs one item.  When that item is found, it no longer searches, right ??  So a conditional statement wouldn't work here.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Question regarding a continuation ...
« Reply #8 on: March 16, 2007, 10:52:07 AM »
Hangman,

You could consolidate all of your layer names and colors into a dotted pair list, and if you continue to use the command route to create the layers, use "make" instead of "new" and you don't have to check if the layer exists.

Something like:

Code: [Select]
(setq mylayers '(("s-beams" . 1) ("S-Solid60" . 23) ("S-Viewport" . 7)))

(foreach lyr mylayers
  (command ".-layer" "Make" (car lyr) "Color" (cdr lyr) "" "")
)

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

JohnK

  • Administrator
  • Seagull
  • Posts: 10651
Re: Question regarding a continuation ...
« Reply #9 on: March 16, 2007, 10:55:38 AM »
Did you read that methods document?

I gotta get something done right now, but ill talk more in a sec.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10651
Re: Question regarding a continuation ...
« Reply #10 on: March 16, 2007, 07:09:37 PM »
Hangman, did you read my document yet?

TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Hangman

  • Swamp Rat
  • Posts: 566
Re: Question regarding a continuation ...
« Reply #11 on: March 16, 2007, 08:01:37 PM »
Hangman,

You could consolidate all of your layer names and colors into a dotted pair list, and if you continue to use the command route to create the layers, use "make" instead of "new" and you don't have to check if the layer exists.

Ron

Excellent.  I didn't know I could do that with a dotted pair for making a layer.
Question;  Would the "make" command create the layer regardless of if it exists or not ??
I need to play with this and see what I can do.
Thank you Ron.

Hangman, did you read my document yet?


Yessir, I have now read it.   Sorry it took so long, I don't get a lot of time to do much coding, but I really enjoy learning it when I do get the time.  I think that's one reason why I'm always in such a rush when I get online here, I don't have much time.   :-(
The Methods is a very good & informative read.
I had actually started my program as a two or three abstraction program (I was running into problems and for me it was easier to make it a single piece I could follow to find the problems), I never thought of breaking it down even more as was mentioned in the Methods.
Question; Do you have to reference each segment or can you get away without referencing each piece as you described in the document ??  I'm not sure by the wording of the document if you are giving a brief example or if the code you show is acceptable as is.  Does that make sence what I am asking ??  I know the point you are trying to put across is to practice the design of abstraction coding.
Quote
  (defun Slope ( line / GetData GetStartPoint GetEndPoint
   DeltaY DeltaX rise run )

    (defun GetData ( code )
      (cdr
        (assoc code (entget line))
      )
    )
  Would I tell the program "GOTO GetStartPoint" here ??
    (defun GetStartPoint ( )
      (GetData 10)
    )
  Would I tell the program "GOTO GetEndPoint" here ??
    (defun GetEndPoint ( )
      (GetData 11)
    )
  Would I tell the program "GOTO DeltaY" here ??
    (defun DeltaY ( StartPoint EndPoint )
      (-
        (cadr StartPoint)
        (cadr EndPoint)
      )
    )
  Would I tell the program "GOTO DeltaX" here ??
    (defun DeltaX (StartPoint EndPoint)
      (-
        (car StartPoint)
        (car EndPoint)
      )
    )
I've programmed DOS BAT files and still have that in my blood.  All too often I keep thinking of the  IF ... GOTO ... concept.  I know I don't have to put in the GOTO, but would I reference the next abstraction or would the program simply go to the next line if there is no reference ??

Anyway, I think I'm getting off track.  Yes, I have read your document, what do you have in mind ??
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Question regarding a continuation ...
« Reply #12 on: March 16, 2007, 08:12:05 PM »
Hangman, what happens when you load that and run it
... other than the message about a missing Parenthesis { I think }
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

JohnK

  • Administrator
  • Seagull
  • Posts: 10651
Re: Question regarding a continuation ...
« Reply #13 on: March 16, 2007, 11:40:07 PM »
The final code in my doc works as is. No, you dont have to ``goto'' any of the `named abstractions' you just use them in the place where you need them.

I was thinking about doing much the same as when i created the generalized ``getdata'' abstraction for your layer check and create procedure.  But i think we need to take a huge step back and define the problem first. I think you should write down--in plain words; no code at all--what you want to do. Then we can start to rebuild your entire procedure.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Hangman

  • Swamp Rat
  • Posts: 566
Re: Question regarding a continuation ...
« Reply #14 on: March 19, 2007, 06:05:39 PM »
Hangman, what happens when you load that and run it
... other than the message about a missing Parenthesis { I think }

Well Kerry, ...  I'm not sure.  I don't think I'm running this vlide correctly.  But when I run it through a drawing with a line, it appears to go all the way through.
Sorry I didn't do this earlier, I wasn't in a position to try it out at the time on a CAD machine.


I was thinking about doing much the same as when i created the generalized ``getdata'' abstraction for your layer check and create procedure.  But i think we need to take a huge step back and define the problem first. I think you should write down--in plain words; no code at all--what you want to do. Then we can start to rebuild your entire procedure.
OK, ... so, in a nutshell.
I have several typical details dating from last week to ... 10 years ago.  They were created in every release from R14 to R2007.
Over the years the font width has changed, in some cases, the font itself has changed in the details.  The layering system has changed, the dimension style has changed ... dramatically.
I also have several schedules ranging in the same dates & releases.  Same situation.
Some of these details & schedules have been updated for printing to DWF but most have not.
The current system for engineers to view the typical details is by DWF rather than binder and 8.5 x 11's.  So my 'hurry up and get it done' instructions is to update all the typical details & schedules & print them off to DWF so the engineers can view the typical details & schedules on their machine rather than passing a 4" binder around.

My individual steps to this goal.
I want to open the detail  (or schedule).
Purge the drawing of any excess shhtuff.
Run the Layer Translator.
 ...

Awww crap, ...  I have to leave.  :(
I'll try to finish this tomorrow.

Back to finish ...  03-20_2007

after running Layer Translator,
I want to create a new Text style.  (Saving this style with the same name as the current style should update all text on the current style at the next regen)
I want to create a new Dimension style.
Modify it to the settings we need & set it as current.
Select all entities regarding any dimension style and set them to the new style.
Delete any layout tab labeled "Layout", "Layout2", "8.5 x 11", "Detail"
Create a new layout tab labeled "8.5x11" by importing from a template.
Move new layout to front of line (if there is one) and set it to current layout tab.
Enter model space through viewport and zoom extents.
Zoom detail to appropriate scale.
If detail exceeds limits of scale, then zoom extents only.
Go back to paper space from viewport.
insert a name block of the detail.
zoom extents.
Go to Model tab.
zoom extents, purge all, save and close.

Go to next detail and do it all over again.

So, there's a list of what I am wanting to accomplish.  I used Tims advice and created a lisp which creates a script for going to the next detail, but I don't know if it's that lisp or this one that won't allow it to go the rounds with all the details.  I get through about three details and it just stops.
Doht, ...  I digress again.
OK, here's the list, what the next step ??
« Last Edit: March 20, 2007, 10:30:00 AM by Hangman »
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~