Author Topic: How to statistics the total number of parts?  (Read 19514 times)

0 Members and 1 Guest are viewing this topic.

xianaihua

  • Guest
How to statistics the total number of parts?
« on: January 05, 2010, 07:23:28 AM »
Hello all,
I want to assemble a body of statistics for each sub-assembly and parts of the total numbers,
Their assembly relation is shown below.


The number behind each piece, but the pieces in the last one in a number of sub-assembly.

According to bom of each dwg,I constructed the following list:
("sub-assembly1-1" "assembly" 2)
("sub-assembly1-2" "assembly" 3)
("sub-assembly1-3" "assembly" 2)
("pat1-1" "assembly" 3)
("pat1-2" "assembly" 2)
("pat1-3" "assembly" 1)
("sub-assembly2-1" "sub-assembly1-1" 3)
("sub-assembly2-2" "sub-assembly1-1" 3)
("sub-assembly2-3" "sub-assembly1-1" 2)
("pat2-1" "sub-assembly1-1" 3)
("pat2-2" "sub-assembly1-1" 2)
("pat1-3" "sub-assembly1-1" 1)
("pat3-1" "sub-assembly2-1" 3)
("pat3-2" "sub-assembly2-1" 2)
("pat2-1" "sub-assembly2-1" 1)

Example:total numbers of "pat3-1"=3X3X2X1
That,numbers of "pat3-1" in the "sub-assembly2-1" *  numbers of "sub-assembly2-1" in the "sub-assembly1-1" * numbers of "sub-assembly1-1" in the "assembly" *  numbers of "assembly"(By default, the top-level assembly's number is one)
I want to have a recursive algorithm, was the total number of new list
("sub-assembly1-1" "assembly" 2 2);2X1
("sub-assembly1-2" "assembly" 3 3);3X1
("sub-assembly1-3" "assembly" 2 2);2X1
("pat1-1" "assembly" 3 3);3X1
("pat1-2" "assembly" 2 2);2X1
("pat1-3" "assembly" 1 1);1X1
("sub-assembly2-1" "sub-assembly1-1" 3 6);3X2X1
("sub-assembly2-2" "sub-assembly1-1" 3 6);3X2X1
("sub-assembly2-3" "sub-assembly1-1" 2 4);2X2X1
("pat2-1" "sub-assembly1-1" 3 6);3X2X1
("pat2-2" "sub-assembly1-1" 2 4);2X2X1
("pat1-3" "sub-assembly1-1" 1 2);1X2X1
("pat3-1" "sub-assembly2-1" 3 18);3X3X2X1
("pat3-2" "sub-assembly2-1" 2 12);2X3X2X1
("pat2-1" "sub-assembly2-1" 1 6);1X3X2X1

All friends, how to do this recursively?

First of all, thanks !



« Last Edit: January 05, 2010, 06:28:24 PM by xianaihua »

xianaihua

  • Guest
Re: How to statistics the total number of parts?
« Reply #1 on: January 05, 2010, 09:56:54 PM »
Hi all..

Anyone have an idea on how to get tol numbers of parts?

thanks.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to statistics the total number of parts?
« Reply #2 on: January 05, 2010, 10:25:00 PM »
Maybe tomorrow, I'm done for the day. :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

xianaihua

  • Guest
Re: How to statistics the total number of parts?
« Reply #3 on: January 06, 2010, 06:56:47 PM »
I look forward to the guidance of CAB, and other masters! :-D

T.Willey

  • Needs a day job
  • Posts: 5251
Re: How to statistics the total number of parts?
« Reply #4 on: January 06, 2010, 07:28:56 PM »
Here is a start.  You can do the recursion changes to make it do what you want exactly.

Code: [Select]
(defun ShowBlockNesting ( blkName blkCol / tempList tempName NestingList)
   
    (if (not (vl-catch-all-error-p (setq BlkObj (vl-catch-all-apply 'vla-Item (list blkCol blkName)))))
        (vlax-for obj BlkObj
            (if (= (vla-get-ObjectName obj) "AcDbBlockReference")
                (if (setq tempList (assoc (setq tempName (vla-get-Name obj)) NestingList))
                    (setq NestingList (subst (cons tempName (1+ (cdr tempList))) tempList NestingList))
                    (setq NestingList (cons (cons tempName 1) NestingList))
                )
            )
        )
    )
    (cons blkName NestingList)
)

(defun c:Test ()
    (showblocknesting (cdr (assoc 2 (entget (car (entsel))))) (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

adalea03

  • Guest
Re: How to statistics the total number of parts?
« Reply #5 on: January 06, 2010, 08:13:09 PM »
No master here, but I would block everything (with attributes).
SSget all the parts, and drill through list(s) , counting as you go.
Sound so simmple, doesn't it?

i.e.
Block A contains 4 distint parts .
Get/count all instances of block A.
(List "Block A" integer-blockcountA  ("subpart1" (* integer-blockcountA qty-subpart1))  ("subpart2" (* integer-blockcountA qty-subpart2)))
                                                        ("subpart3" (* integer-blockcountA qty-subpart3)))  ("subpart4" (* integer-blockcountA) qty-subpart4)))
Block B contains 12 distint parts .
(List "Block B" integer-blockcountB  ("subpart1" (* integer-blockcountB qty-subpart1))   ...

There may be a lot  of "hard coding" necessary to achieve your goal,
but if your needs are specific to your discipline ,
just "Get 'er done", any 'ole way you can.

AA






adalea03

  • Guest
Re: How to statistics the total number of parts?
« Reply #6 on: January 06, 2010, 08:25:58 PM »
Better yet, follow T.Wiley.

xianaihua

  • Guest
Re: How to statistics the total number of parts?
« Reply #7 on: January 07, 2010, 06:10:08 AM »
thanks,

Sorry, my English is poor, not explained clearly.

Now, regardless of anything else, we can reduce the problem only to the list of recursive processing.

In accordance with the above requirements, how the recursive computation of the list? Please express anyone's idea and suggestions!

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to statistics the total number of parts?
« Reply #8 on: January 07, 2010, 09:21:19 AM »
Why does it have to be recursive? Is this a homework assignment?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

xianaihua

  • Guest
Re: How to statistics the total number of parts?
« Reply #9 on: January 07, 2010, 10:10:47 AM »
hi,CAB!

Of course, do not use the recursive method can also be!Doing mechanical design, we often have statistical part quantity.Bom assembly drawings of each style is shown below
« Last Edit: January 07, 2010, 10:27:54 AM by xianaihua »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to statistics the total number of parts?
« Reply #10 on: January 07, 2010, 11:33:00 AM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: How to statistics the total number of parts?
« Reply #11 on: January 07, 2010, 11:33:35 AM »
Why does it have to be recursive? Is this a homework assignment?


I think because I said recursive, as that lends itself to these type of situations.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to statistics the total number of parts?
« Reply #12 on: January 07, 2010, 12:05:14 PM »
Thanks Tim, but at the end of the Op's first post:
Quote
All friends, how to do this recursively?

From futher postings it is obviously not Homework, from school anyway.  :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: How to statistics the total number of parts?
« Reply #13 on: January 07, 2010, 12:12:52 PM »
You pay better attention that I do Alan, as I didn't even see that requirement.   :-D
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to statistics the total number of parts?
« Reply #14 on: January 07, 2010, 12:32:33 PM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: How to statistics the total number of parts?
« Reply #15 on: January 07, 2010, 12:57:44 PM »
Here is one I just wrote.  Seemed fun, and I need to stretch the grey matter.
Code: [Select]
(defun c:ShowNesting (/ *error* ActDoc BlkCol Sel EntData BlkName NestList)
   
    (defun *error* ( msg )
       
        (vl-bt)
    )
    ;------------------------------
    (defun GetBlockBlocks ( blkObj doc / BlkCol BlkCntList tempList tempName )
       
        (setq BlkCol (vla-get-Blocks doc))
        (vlax-for obj blkObj
            (if (= (vla-get-ObjectName obj) "AcDbBlockReference")
                (setq BlkCntList
                    (if (setq tempList (assoc (setq tempName (vla-get-Name obj)) BlkCntList))
                        (subst (list tempName (1+ (cadr tempList)) (caddr tempList)) tempList BlkCntList)
                        (cons (list tempName 1(GetBlockBlocks (vla-Item BlkCol tempName) doc)) BlkCntList)
                    )
                )
            )
        )
        BlkCntList
    )
    ;-------------------------------------
    (defun PrintList ( lst indent )
       
        (prompt (strcat "\n" indent (car lst) " - " (itoa (cadr lst))))
        (foreach i (caddr lst)
            (PrintList i (strcat "    " indent))
        )
    )
    ;-------------------------------------
    (setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
    (setq BlkCol (vla-get-Blocks ActDoc))
    (if
        (and
            (setq Sel (entsel "\n Select block to get nesting block list: "))
            (setq EntData (entget (car Sel)))
            (= (cdr (assoc 0 EntData)) "INSERT")
            (setq BlkName (cdr (assoc 2 EntData)))
            (setq NestList (GetBlockBlocks (vla-Item BlkCol BlkName) ActDoc))
        )
        (progn
            (prompt (strcat "\nReport for:" BlkName))
            (foreach lst NestList
                (PrintList lst "    ")
            )
        )
    )
    (princ)
)
Returns to the command line
Quote
Report for:testing
    test - 3
        DI-NOTE - 1
        CIR-NOTE - 4
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: How to statistics the total number of parts?
« Reply #16 on: January 07, 2010, 01:04:02 PM »
Another bit of code looking at nested blocks, not sure whether it helps?

http://www.theswamp.org/index.php?topic=29988.0

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to statistics the total number of parts?
« Reply #17 on: January 07, 2010, 01:11:55 PM »
Looked good on my test Tim. 8-)
Code: [Select]
Select block to get nesting block list:
Report for:sub-ass2-1
    sub-ass-1 - 2
        part-1 - 1
        part-2 - 1
        part-3 - 1
    sub-ass-2 - 1
        part-3 - 1
        part-2 - 1
        part-1 - 1
    sub-ass-3 - 1
        part-3 - 1
        part-2 - 1
        part-1 - 1
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: How to statistics the total number of parts?
« Reply #18 on: January 07, 2010, 01:14:12 PM »
Thanks Alan.  I didn't have too many nested blocks, so I just created a simple one.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

xianaihua

  • Guest
Re: How to statistics the total number of parts?
« Reply #19 on: January 07, 2010, 07:13:18 PM »
Thanks Alan,Tim

Thank you for your reply.You spent valuable time



In mechanical design, in each assembly has a bom, the bom sets out the assembly of all the sub-assembly and parts of some information, such as: code, name, quantity, material, weight, etc., but these sub - assembly and parts in the model space is not necessarily a block reference, may be a  line, arc, pline, etc., bom data is entered manually. It is not possible with the search block refer to the number of ways of doing.



The question now is: can be a folder of all the following dwg files of these bom data extraction, and how to process these data?
« Last Edit: January 07, 2010, 07:20:41 PM by xianaihua »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How to statistics the total number of parts?
« Reply #20 on: January 07, 2010, 07:46:31 PM »
xianaihua,

Are you exporting each BOM to a .CSV file ??

if yes ;
is there a seperate .CSV file for each assembly ?
and ; are the CSV files the same name as the assembly ?

How are you generating the lists shown in your first post ??

Regards
Kerry

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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to statistics the total number of parts?
« Reply #21 on: January 07, 2010, 07:53:42 PM »
It would help if you supplied a sample DWG file.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

xianaihua

  • Guest
Re: How to statistics the total number of parts?
« Reply #22 on: January 08, 2010, 01:44:03 AM »
xianaihua,

Are you exporting each BOM to a .CSV file ??

if yes ;
is there a seperate .CSV file for each assembly ?
and ; are the CSV files the same name as the assembly ?

How are you generating the lists shown in your first post ??

Regards
Kerry


Hi,Kerry
I exporting all BOM from assembly's dwg(a folder of all the following dwg files )  to a database (.mdb) file .

xianaihua

  • Guest
Re: How to statistics the total number of parts?
« Reply #23 on: January 08, 2010, 01:50:17 AM »
It would help if you supplied a sample DWG file.

ok,I have supplied a sample DWG file and BOM.txt file.

xianaihua

  • Guest
Re: How to statistics the total number of parts?
« Reply #24 on: November 01, 2011, 11:37:09 PM »
Hi,all
I had already won the way to solve this problem, the following is my practice, everyone please review a review, or give some advice
Code: [Select]
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;;
;;                                                                               ;;
;;  AUTHOR:  lihuaili, November 2011.                                            ;;
;;...............................................................................;;
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;;
;;;In the schedule list, statistics a part in code number
;;;Statistical method: first find out the parts in the assembly code father quantity, to find the father in the more higher level assembly father assemble number... ,
;;;And so on, until inquires the top to assembly, the number of these factors, and that of the parts of the total number.
;;;I through trial and error, finally using a recursive method solved the difficult problem.
;;;Parameters:
;;;Bom_lst: bom all list; 【 list 】
;;;Assemble_No: father assembly code; 【 str 】
;;;Part_No_index: spare parts list list adept in code in the list of the index number (note: the first listed as 0) 【 INT 】
;;;Assemble_No_index: assembly code in the list belong to the list of the index number list adept 【 INT 】
;;;Num_index: in its parts assembly (father assembly) of the quantity, understood in the list of the index number list adept 【 INT 】
;;;return:
;;;Total number 【INT】

(defun SumPartCounts (bom_lst       assemble_No     part_No_index
      assemble_No_index       Num_index
      /       tol_num
     )
  (or tol_num (setq tol_num 1))
  (foreach x bom_lst
    (if (= assemble_No (nth part_No_index x))
      (setq assemble_No (nth assemble_No_index x)
    tol_num (* tol_num
   (atoi (nth Num_index x))
   (SumPartCounts
     bom_lst        assemble_No
     part_No_index     assemble_No_index
     Num_index
    ) ;_ 结束SumPartCounts
 ;_ 结束SumPartCounts
) ;_ 结束*
      ) ;_ 结束setq
    ) ;_ 结束if

  ) ;_ 结束foreach
  tol_num
) ;_ 结束defun

;;;writie list data  to the text file
(defun WriteDataFile (file_name data_lst / _tostring file)
;by:Lee Mac
  (defun _tostring (x / dimzin)
    (cond
      ((eq 'INT (type x))
       (itoa x)
      )
      ((eq 'REAL (type x))
       (setq dimzin (getvar 'DIMZIN))
       (setvar 'DIMZIN 0)
       (setq x (rtos x 2 8))
       (setvar 'DIMZIN dimzin)
       x
      )
      ((vl-prin1-to-string x))
    ) ;_ 结束cond
  ) ;_ 结束defun

  (if (setq file (open file_name "w"))
    (progn
      (foreach x data_lst (write-line (_tostring x) file))
      (setq file (close file))
      t
    ) ;_ 结束progn
  ) ;_ 结束if
) ;_ 结束defun

;;;bomlst:Is the way to get through some parts list (list specific methods in this not discussed)
;;;Among them the first listed as parts of each line of code
;;;The second listed as parts assembly code belongs
;;;The third listed as in its parts assembly of quantity

(setq bomlst '(
       ("sub-assembly1-1" "assembly" "2")
       ("sub-assembly1-2" "assembly" "3")
       ("sub-assembly1-3" "assembly" "1")
       ("pat1-1" "assembly" "3")
       ("pat1-2" "assembly" "2")
       ("pat1-3" "assembly" "5")
       ("sub-assembly2-1" "sub-assembly1-1" "2")
       ("sub-assembly2-2" "sub-assembly1-1" "2")
       ("sub-assembly2-3" "sub-assembly1-1" "4")
       ("pat2-1" "sub-assembly1-1" "3")
       ("pat2-2" "sub-assembly1-1" "4")
       ("pat1-3" "sub-assembly1-1" "2")
       ("pat3-1" "sub-assembly2-1" "2")
       ("pat3-2" "sub-assembly2-1" "3")
       ("pat2-1" "sub-assembly2-1" "1")
      )
) ;_ 结束setq
(defun c:test (/ partnumlst Ap_No p_num partnumlst fname)
  (setq partnumlst '())
  (foreach n (reverse bomlst)
    (setq Ap_No      (nth 1 n)
  p_num      (atoi (nth 2 n))
  partnumlst
     (cons
       (append n
       (list (itoa (* (SumPartCounts bomlst Ap_No 0 1 2) p_num)))
       ) ;_ 结束append
       partnumlst
     ) ;_ 结束cons
    ) ;_ 结束setq
  ) ;_ 结束foreach

  (setq
    fname (getfiled "save list data input filename";

    (getvar "dwgprefix")
    "txt"
    3
  ) ;_ 结束getfiled
  ) ;_ 结束setq
  (if fname
    (progn
      (WriteDataFile fname partnumlst)
      (alert "The current data has been preserved!");
    ) ;_ 结束progn
  ) ;_ 结束if
) ;_ 结束defun
« Last Edit: December 04, 2011, 07:51:56 PM by xianaihua »

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: How to statistics the total number of parts?
« Reply #25 on: November 21, 2011, 03:38:09 PM »
ElpanovEvgeniy
Good weekend!
If you have time, please optimization or simplify my program In the following posts。
Thanks agan!
http://www.theswamp.org/index.php?topic=31524.msg452218#msg452218

:)

Hi,all
I had already won the way to solve this problem, the following is my practice, everyone please review a review, or give some advice
Code: [Select]
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;;
;;                                                                               ;;
;;  AUTHOR:  lihuaili, November 2011.                                            ;;
;;...............................................................................;;
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;;
;;;In the schedule list, statistics a part in code number
;;;Statistical method: first find out the parts in the assembly code father quantity, to find the father in the more higher level assembly father assemble number... ,
;;;And so on, until inquires the top to assembly, the number of these factors, and that of the parts of the total number.
;;;I through trial and error, finally using a recursive method solved the difficult problem.
;;;Parameters:
;;;Bom_lst: bom all list; 【 list 】
;;;Assemble_No: father assembly code; 【 str 】
;;;Part_No_index: spare parts list list adept in code in the list of the index number (note: the first listed as 0) 【 INT 】
;;;Assemble_No_index: assembly code in the list belong to the list of the index number list adept 【 INT 】
;;;Num_index: in its parts assembly (father assembly) of the quantity, understood in the list of the index number list adept 【 INT 】
;;;return:
;;;Total number 【INT】

(defun SumPartCounts (bom_lst       assemble_No     part_No_index
      assemble_No_index       Num_index
      /       tol_num
     )
  (or tol_num (setq tol_num 1))
  (foreach x bom_lst
    (if (= assemble_No (nth part_No_index x))
      (setq assemble_No (nth assemble_No_index x)
    tol_num (* tol_num
   (atoi (nth Num_index x))
   (SumPartCounts
     bom_lst        assemble_No
     part_No_index     assemble_No_index
     Num_index
    ) ;_ 结束SumPartCounts
 ;_ 结束SumPartCounts
) ;_ 结束*
      ) ;_ 结束setq
    ) ;_ 结束if

  ) ;_ 结束foreach
  tol_num
) ;_ 结束defun

;;;writie list data  to the text file
(defun WriteDataFile (file_name data_lst / _tostring file)
  (defun _tostring (x / dimzin)
    (cond
      ((eq 'INT (type x))
       (itoa x)
      )
      ((eq 'REAL (type x))
       (setq dimzin (getvar 'DIMZIN))
       (setvar 'DIMZIN 0)
       (setq x (rtos x 2 8))
       (setvar 'DIMZIN dimzin)
       x
      )
      ((vl-prin1-to-string x))
    ) ;_ 结束cond
  ) ;_ 结束defun

  (if (setq file (open file_name "w"))
    (progn
      (foreach x data_lst (write-line (_tostring x) file))
      (setq file (close file))
      t
    ) ;_ 结束progn
  ) ;_ 结束if
) ;_ 结束defun

;;;bomlst:Is the way to get through some parts list (list specific methods in this not discussed)
;;;Among them the first listed as parts of each line of code
;;;The second listed as parts assembly code belongs
;;;The third listed as in its parts assembly of quantity

(setq bomlst '(
       ("sub-assembly1-1" "assembly" "2")
       ("sub-assembly1-2" "assembly" "3")
       ("sub-assembly1-3" "assembly" "1")
       ("pat1-1" "assembly" "3")
       ("pat1-2" "assembly" "2")
       ("pat1-3" "assembly" "5")
       ("sub-assembly2-1" "sub-assembly1-1" "2")
       ("sub-assembly2-2" "sub-assembly1-1" "2")
       ("sub-assembly2-3" "sub-assembly1-1" "4")
       ("pat2-1" "sub-assembly1-1" "3")
       ("pat2-2" "sub-assembly1-1" "4")
       ("pat1-3" "sub-assembly1-1" "2")
       ("pat3-1" "sub-assembly2-1" "2")
       ("pat3-2" "sub-assembly2-1" "3")
       ("pat2-1" "sub-assembly2-1" "1")
      )
) ;_ 结束setq
(defun c:test (/ partnumlst Ap_No p_num partnumlst fname)
  (setq partnumlst '())
  (foreach n (reverse bomlst)
    (setq Ap_No      (nth 1 n)
  p_num      (atoi (nth 2 n))
  partnumlst
     (cons
       (append n
       (list (itoa (* (SumPartCounts bomlst Ap_No 0 1 2) p_num)))
       ) ;_ 结束append
       partnumlst
     ) ;_ 结束cons
    ) ;_ 结束setq
  ) ;_ 结束foreach

  (setq
    fname (getfiled "save list data input filename";

    (getvar "dwgprefix")
    "txt"
    3
  ) ;_ 结束getfiled
  ) ;_ 结束setq
  (if fname
    (progn
      (WriteDataFile fname partnumlst)
      (alert "The current data has been preserved!");
    ) ;_ 结束progn
  ) ;_ 结束if
) ;_ 结束defun

my variant:
Code: [Select]
(defun test (l / f)
  (defun f (a l) (if a (* (atoi (caddr a)) (f (assoc (cadr a) l) l)) 1))
  (mapcar (function (lambda (a) (append a (list (itoa (f a l)))))) l)
)

check:
Code: [Select]
(setq l '(("sub-assembly1-1" "assembly" "2")
               ("sub-assembly1-2" "assembly" "3")
               ("sub-assembly1-3" "assembly" "1")
               ("pat1-1" "assembly" "3")
               ("pat1-2" "assembly" "2")
               ("pat1-3" "assembly" "5")
               ("sub-assembly2-1" "sub-assembly1-1" "2")
               ("sub-assembly2-2" "sub-assembly1-1" "2")
               ("sub-assembly2-3" "sub-assembly1-1" "4")
               ("pat2-1" "sub-assembly1-1" "3")
               ("pat2-2" "sub-assembly1-1" "4")
               ("pat1-3" "sub-assembly1-1" "2")
               ("pat3-1" "sub-assembly2-1" "2")
               ("pat3-2" "sub-assembly2-1" "3")
               ("pat2-1" "sub-assembly2-1" "1")
              )
)
Code: [Select]
(test l)
>>
(("sub-assembly1-1" "assembly" "2" "2")
  ("sub-assembly1-2" "assembly" "3" "3")
  ("sub-assembly1-3" "assembly" "1" "1")
  ("pat1-1" "assembly" "3" "3")
  ("pat1-2" "assembly" "2" "2")
  ("pat1-3" "assembly" "5" "5")
  ("sub-assembly2-1" "sub-assembly1-1" "2" "4")
  ("sub-assembly2-2" "sub-assembly1-1" "2" "4")
  ("sub-assembly2-3" "sub-assembly1-1" "4" "8")
  ("pat2-1" "sub-assembly1-1" "3" "6")
  ("pat2-2" "sub-assembly1-1" "4" "8")
  ("pat1-3" "sub-assembly1-1" "2" "4")
  ("pat3-1" "sub-assembly2-1" "2" "8")
  ("pat3-2" "sub-assembly2-1" "3" "12")
  ("pat2-1" "sub-assembly2-1" "1" "4")
)

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: How to statistics the total number of parts?
« Reply #26 on: November 21, 2011, 03:53:38 PM »
Hi,  xianaihua! :)

I'm not sure that is true to understand the purpose of the program.
I have done the same result with your code...


xianaihua

  • Guest
Re: How to statistics the total number of parts?
« Reply #27 on: November 21, 2011, 07:04:17 PM »
Hi,  xianaihua! :)

I'm not sure that is true to understand the purpose of the program.
I have done the same result with your code...

Hi,Evgeniy
excellent!!!
Thanks you help me!
This is what I wanted the results.You is a true recursion experts, you of the recursive use of magic.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: How to statistics the total number of parts?
« Reply #28 on: November 22, 2011, 02:35:22 AM »
Hi,Evgeniy
excellent!!!
Thanks you help me!
This is what I wanted the results.You is a true recursion experts, you of the recursive use of magic.


In 2006, I published an article "Lessons from the creation of recursive functions."
You may be interested in reading this series of lessons...
 :-)
Recursion in AutoLISP Lesson 1
Recursion in AutoLISP Lesson 2
Recursion in AutoLISP Lesson 3
Recursion in AutoLISP Lesson 4
Recursion in AutoLISP Lesson 5
Recursion in AutoLISP Lesson 6
Recursion in AutoLISP Lesson 7
Recursion in AutoLISP Lesson 8
Recursion in AutoLISP Lesson 9
Recursion in AutoLISP Lesson 10

nivuahc

  • Guest
Re: How to statistics the total number of parts?
« Reply #29 on: November 22, 2011, 09:16:13 AM »
ElpanovEvgeniy,

What are the chances that you'd be willing to put that together in a single PDF, available for download?

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: How to statistics the total number of parts?
« Reply #30 on: November 22, 2011, 09:19:19 AM »
ElpanovEvgeniy,

What are the chances that you'd be willing to put that together in a single PDF, available for download?

in Russian - no problems with quality translation I can not ...

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: How to statistics the total number of parts?
« Reply #31 on: November 22, 2011, 09:24:04 AM »
Do you want to translate into English?

nivuahc

  • Guest
Re: How to statistics the total number of parts?
« Reply #32 on: November 22, 2011, 09:35:19 AM »
Do you want to translate into English?

I can take a crack at it, as time permits. Unfortunately time is in short supply for me.


GDF

  • Water Moccasin
  • Posts: 2081
Re: How to statistics the total number of parts?
« Reply #33 on: November 22, 2011, 03:12:42 PM »
Thanks Alan.  I didn't have too many nested blocks, so I just created a simple one.

Works great for nested xrefs...sexy.
Thanks Tim for sharing it.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to statistics the total number of parts?
« Reply #34 on: November 23, 2011, 11:01:35 PM »
Do you want to translate into English?

I can take a crack at it, as time permits. Unfortunately time is in short supply for me.

I did a copy & paste to HTML then print to DOC format to get a pretty good document.
Although I lost font colors and some of the code was missing LF CRs but I have edited it into a fairly clean document.
I set all code to red & managed to re-color the first two pages of code but there are some 43 pages so I stopped there.
No more time but I can forward the DOC file if you want to take it to the next level. (with Evgeniy's permission of course)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: How to statistics the total number of parts?
« Reply #35 on: December 04, 2011, 11:59:02 AM »
Code: [Select]
. . .

;;;writie list data  to the text file
(defun WriteDataFile (file_name data_lst / _tostring file)
  (defun _tostring (x / dimzin)
    (cond
      ((eq 'INT (type x))
       (itoa x)
      )
      ((eq 'REAL (type x))
       (setq dimzin (getvar 'DIMZIN))
       (setvar 'DIMZIN 0)
       (setq x (rtos x 2 8))
       (setvar 'DIMZIN dimzin)
       x
      )
      ((vl-prin1-to-string x))
    ) ;_ 结束cond
  ) ;_ 结束defun

  (if (setq file (open file_name "w"))
    (progn
      (foreach x data_lst (write-line (_tostring x) file))
      (setq file (close file))
      t
    ) ;_ 结束progn
  ) ;_ 结束if
) ;_ 结束defun

. . .

Code: [Select]
(defun NumInc:WriteConfig ( name lst / _tostring file )

    (defun _tostring ( x / dimzin )
        (cond
            (   (eq 'INT (type x))
                (itoa x)
            )
            (   (eq 'REAL (type x))
                (setq dimzin (getvar 'DIMZIN))
                (setvar 'DIMZIN 0)
                (setq x (rtos x 2 8))
                (setvar 'DIMZIN dimzin)
                x
            )
            (   (vl-prin1-to-string x)   )
        )
    )
   
    (if (setq file (open name "w"))
        (progn
            (foreach x lst (write-line (_tostring x) file))
            (setq file (close file))
            t
        )
    )
)

  :-o

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: How to statistics the total number of parts?
« Reply #36 on: December 04, 2011, 12:20:10 PM »
Why should (setq file (close file))?
Perhaps just enough (close file)...

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: How to statistics the total number of parts?
« Reply #37 on: December 04, 2011, 12:22:10 PM »
Why should (setq file (close file))?
Perhaps just enough (close file)...

Because 'close' always returns nil, so I use it to null the 'file' variable. This way I can check for the 'file' variable in my *error* handler.

xianaihua

  • Guest
Re: How to statistics the total number of parts?
« Reply #38 on: December 04, 2011, 08:15:11 PM »
Hi,lee !
sorry!
Forget your copyright :ugly:
This is a good tool!