Author Topic: If statement with inserting dwgs  (Read 1314 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Gator
  • Posts: 2603
  • I can't remeber what I already asked! I need help!
If statement with inserting dwgs
« on: July 10, 2018, 07:32:29 AM »
I have a basic routine that inserts details into a blank drawing. I ran into this issue this morning. I ran the routine and in the middle of it; the routine had an error out.

The problem was that the detail got renamed.

So this is my question. Is there an if statement I could use if a detail (That its trying to insert) is not available that it can skip it and go onto the next one?

Code: [Select]
(command "._insert" "//Server1/Details/BEDDING RCP.dwg" "3.4086,18.0777" "" "" "")
(command "._insert" "//Server1/Details/BEDDING PVC.dwg" "10.4322,17.8681" "" "" "")
(command "._insert" "//Server1/Details/SANITARY CROSSOVER & SEPERATION REQ.dwg" "18.2376,12.2324" "" "" "")
(command "._insert" "//Server1/Details/SANITARY CLEANOUT.dwg" "26.9325,12.6906" "" "" "")
(command "._insert" "//Server1/Details/STORM MANHOLE TYPE C.dwg" "18.9855,17.8591" "" "" "")
Civil3D 2020

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: If statement with inserting dwgs
« Reply #1 on: July 10, 2018, 08:03:47 AM »
Perhaps something like this?

Code - Auto/Visual Lisp: [Select]
  1. (setq fn "//Server1/Details/SANITARY CROSSOVER & SEPERATION REQ.dwg")
  2. (if (findfile fn)
  3.   (command "insert" fn ...... )
  4. )
  5.  
« Last Edit: July 10, 2018, 08:52:34 AM by rkmcswain »

kpblc

  • Bull Frog
  • Posts: 396
Re: If statement with inserting dwgs
« Reply #2 on: July 10, 2018, 08:10:09 AM »
Another one:
Code - Auto/Visual Lisp: [Select]
  1. (defun test (/ err)
  2.   (foreach item '((("name" . "//Server1/Details/BEDDING RCP.dwg") ("pt" 3.4086 18.0777))
  3.                   (("name" . "//Server1/Details/BEDDING PVC.dwg") ("pt" 10.4322 17.8681))
  4.                   ;; <...>
  5.                   )
  6.     (if (findfile (cdr (assoc "name" item)))
  7.                        (vlax-3d-point (cdr (assoc "pt" item)))
  8.                        (cdr (assoc "name" item))
  9.                        1.
  10.                        1.
  11.                        1.
  12.                        0.
  13.                        ) ;_ end of vla-InsertBlock
  14.       (setq err (cons (cdr (assoc "name" item)) err))
  15.       ) ;_ end of if
  16.     ) ;_ end of foreach
  17.   (if err
  18.     (princ
  19.       (strcat "\nThese blocks didn't inserted:"
  20.               (apply (function strcat) (mapcar (function (lambda (x) (strcat "\n" x))) (vl-sort err '<)))
  21.               ) ;_ end of strcat
  22.       ) ;_ end of princ
  23.     ) ;_ end of if
  24.   (princ)
  25.   ) ;_ end of defun
Sorry for my English.

ur_naz

  • Newt
  • Posts: 68
  • Made in Ukraine
Re: If statement with inserting dwgs
« Reply #3 on: July 10, 2018, 08:23:09 AM »
insert from anywhere, can be smartly used with mapcar or foreach then inserting from the same directory
Code - Auto/Visual Lisp: [Select]
  1. ;; (insert-blk '(0 0) "BEDDING RCP.dwg" "//Server1/Details/")
  2. (defun insert-blk (pt blk_name blk_path / blk_fullname)
  3.     (setq blk_fullname (strcat blk_path blk_name))
  4.     (if (finddile blk_fullname)
  5.         (command "._insert" blk_fullname pt "" "" "")
  6.         (princ (strcat "\nCant find block - " blk_name))))

MSTG007

  • Gator
  • Posts: 2603
  • I can't remeber what I already asked! I need help!
Re: If statement with inserting dwgs
« Reply #4 on: July 10, 2018, 10:27:50 AM »
Thank you guys for all the different ways to do this.
Civil3D 2020