myoujou cain Posted September 14, 2018 Posted September 14, 2018 so i am trying to create an entire system so that i can engineer an electronic schematic with about 3 button presses. most of it is done however i have run into a wall on the last part witch is exporting a bill of materials. the issue is that i need to essentially run the data extraction wizard from the command line, witch as far as i am aware (PLEASE CORRECT ME IF I'M WRONG) can not be done. so i have set to the task of recreating the wizard for the command line, more or less that is. but now i need help, i have attached a copy of my code (largely borrowed from various people). it originaly was to print the block name and handle, i have no need for those so i have been attempting to remove them but now when i run the script it creates a sheet like this: nil N/a (TAG . TD65) N/a 15 18 (TAG . TD66) N/a 12 13 nil N/a nil N/a nil N/a (TAG . TD) N/a (TAG . TD69) N/a 15 16 nil N/a (TAG . CR32) N/a (TAG . CR) N/a (TAG . SW5) N/a (TAG . TD66) N/a 15 16 (TAG . LT3) N/a TAG is the name of a tag that i want included in the list, i am not sure why it is printing like that, and N/a is where the handle used to go but i cant seem to get rid of it printing it... any help on this would be great. also in the end i want to combine this excel file with another one, similar to the way the data extraction command allows you to include outside data, any help with how to get that working would be appreciated as well. ATTOUT.LSP Quote
dlanorh Posted September 14, 2018 Posted September 14, 2018 If you have a test drawing could you save it in AC2010 format and attach it to a new post. It would be a great help in debugging your code. Quote
myoujou cain Posted September 14, 2018 Author Posted September 14, 2018 here is a test drawing example 1.dwg Quote
JuniorNogueira Posted September 15, 2018 Posted September 15, 2018 Was it something like that? ;Gilles Chanteau ;Modified by Júnior Nogueira (defun c:Demo (/ ss file i) (if (setq ss (ssget "_X" '((0 . "INSERT") (66 . 1) (2 . "test,`*U*")))) (progn (setq file (open (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname)) ".csv") "w")) (repeat (setq i (sslength ss)) (setq br (ssname ss (setq i (1- i)))) (if (= (getpropertyvalue (getpropertyvalue br "BlockTableRecord") "Name") "test") (write-line (strcat (getpropertyvalue br "TAG") "," (getpropertyvalue br "PN") "," (getpropertyvalue br "FIND#") "," (getpropertyvalue br "SORT") "," (getpropertyvalue br "QUANTITY") ) file ) ) ) (close file) ) ) (princ) ) Quote
myoujou cain Posted September 17, 2018 Author Posted September 17, 2018 Junior Nogueira, that looks like it might work, but I might need help integrating it into the existing program. specifically, how do I add the object selection.. I'm not very familiar with the SS functions. Quote
dlanorh Posted September 17, 2018 Posted September 17, 2018 On 14/09/2018 at 20:37, myoujou cain said: so i am trying to create an entire system so that i can engineer an electronic schematic with about 3 button presses. most of it is done however i have run into a wall on the last part witch is exporting a bill of materials. the issue is that i need to essentially run the data extraction wizard from the command line, witch as far as i am aware (PLEASE CORRECT ME IF I'M WRONG) can not be done. so i have set to the task of recreating the wizard for the command line, more or less that is. but now i need help, i have attached a copy of my code (largely borrowed from various people). it originaly was to print the block name and handle, i have no need for those so i have been attempting to remove them but now when i run the script it creates a sheet like this: nil N/a (TAG . TD65) N/a 15 18 (TAG . TD66) N/a 12 13 nil N/a nil N/a nil N/a (TAG . TD) N/a (TAG . TD69) N/a 15 16 nil N/a (TAG . CR32) N/a (TAG . CR) N/a (TAG . SW5) N/a (TAG . TD66) N/a 15 16 (TAG . LT3) N/a TAG is the name of a tag that i want included in the list, i am not sure why it is printing like that, and N/a is where the handle used to go but i cant seem to get rid of it printing it... any help on this would be great. also in the end i want to combine this excel file with another one, similar to the way the data extraction command allows you to include outside data, any help with how to get that working would be appreciated as well. ATTOUT.LSP The code below will get every attributed block in the drawing and extract every tag and value pair in the block in the format : (("TAG1" . "VALUE1") ("TAG2" . "VALUE2") ...("*CONSTANT*: TAGN" . "VALUEN")) I've attached the drawing you sent with a modified test block. This now contains an invisible constant attribute (TAG "BLK_NAME" VALUE "TEST") CODE: ;; Get all tags and values from block including constant attributes in following form: ;; (("TAG1" . "VALUE1") ("TAG2" . "VALUE2") ...("*CONSTANT*: TAGN" . "VALUEN")) (defun get-all-atts ( obj / att_lst catt_lst lst tag ) (setq att_lst (append (vlax-invoke obj 'getattributes) (setq catt_lst (vlax-invoke obj 'getconstantattributes))) lst nil );end_setq (foreach att att_lst (setq tag (vla-get-tagstring att)) (if (member att catt_lst) (setq lst (cons (cons (strcat "*CONSTANT*: " tag) (vla-get-textstring att)) lst)) (setq lst (cons (cons tag (vla-get-textstring att)) lst)) );end_if );end_foreach (setq lst (reverse lst)) );end_defun ;; Main part ;; (defun C:ATOUT ( / adoc axss com_data tot) (vl-load-com) (setq adoc (vla-get-activedocument (vlax-get-acad-object)) osm (getvar "osmode") );end_setq (vla-endundomark adoc) (vla-startundomark adoc) (setvar "osmode" 0) (setvar "cmdecho" 0) (cond ( (ssget "_X" (list (cons 0 "INSERT")(cons 66 1)));;This will get you all attributed blocks in the drawing (setq com_data nil) (vlax-for a (setq axss (vla-get-activeselectionset adoc)) (setq com_data (cons (get-all-atts a) com_data)) );end_for (setq com_data (reverse com_data) tot (length com_data) );end_setq ) );end_cond (foreach x com_data (princ x) (princ "\n") );end_foreach (princ) (setvar "osmode" 0) (vla-endundomark adoc) );end_defun There was a lot of superfluous code and I think this was interfering with what was collected and printing to excel. I will look at the excel part next. example 1.dwg Quote
myoujou cain Posted September 18, 2018 Author Posted September 18, 2018 Dlanorh, thank you. this is much cleaner and i was able to change the selection from the whole drawing to a selection (something that is important for my application). there is one issue with this code however. that is that it grabs all the attributes, i only want to print the 5 i have listed. in my drawing the blocks have many attributes that are important for the drawing but not for my BOM. maybe you know of a way to only print those 5? or how to get the lisp to only pull those 5. also i do not need the "("*constant*: tagn" . "valuen") part and i really do not want it showing up in excel. i don't know if that is needed or not for the lisp to function. regardless you have given me an even better place to start from. i will be playing around with this and let know you know if i get anywhere. thanks, Quote
maratovich Posted September 18, 2018 Posted September 18, 2018 I do not quite understand, but maybe you need something like this: "Shema" ? Quote
dlanorh Posted September 18, 2018 Posted September 18, 2018 6 hours ago, myoujou cain said: There is one issue with this code however. that is that it grabs all the attributes, i only want to print the 5 i have listed. in my drawing the blocks have many attributes that are important for the drawing but not for my BOM. maybe you know of a way to only print those 5? or how to get the lisp to only pull those 5. also i do not need the "("*constant*: tagn" . "valuen") part and i really do not want it showing up in excel. i don't know if that is needed or not for the lisp to function. regardless you have given me an even better place to start from. i will be playing around with this and let know you know if i get anywhere. thanks, If you let me know what the five Tag String names are I can adjust the code. I also need to know if any of them are constant attributes, since it would be pointless getting and appending constant attributes if they are not needed. Quote
myoujou cain Posted September 18, 2018 Author Posted September 18, 2018 maratovich- maybe its hard to tell because I don't read that language. dlanorh- none of them are constants, the tag names are: "TAG" "PN" "FIND" "SORT" "QUANTITY" I was able to figure out one way of doing this on my own but i feel like there is a much better way. so i look forward to seeing how you would limit it to only those five attributes. also i am looking forward to seeing how you write this info to excel. what i had made no sense to me lol. THANKS. Quote
dlanorh Posted September 18, 2018 Posted September 18, 2018 (edited) I've probably done it the same way you have, but i've also adjusted the main routine to account for a nil return from the sub function (block has none of the tags). (defun get-all-atts ( obj / att_lst r_lst lst tag ) (setq att_lst (vlax-invoke obj 'getattributes) r_lst (list "TAG" "PN" "FIND" "SORT" "QUANTITY") lst nil );end_setq (foreach att att_lst (setq tag (vla-get-tagstring att)) (if (member tag r_lst) (setq lst (cons (cons tag (vla-get-textstring att)) lst)) );end_if );end_foreach (if (> (length lst) 1) (setq lst (reverse lst))) );end_defun ;; Main part ;; (defun C:ATOUT ( / adoc osm axss tmp com_data tot) (vl-load-com) (setq adoc (vla-get-activedocument (vlax-get-acad-object)) osm (getvar "osmode") );end_setq (vla-endundomark adoc) (vla-startundomark adoc) (setvar "osmode" 0) (setvar "cmdecho" 0) (cond ( (ssget "_X" (list (cons 0 "INSERT")(cons 66 1)));;This will get you all attributed blocks in the drawing (setq com_data nil) (vlax-for a (setq axss (vla-get-activeselectionset adoc)) (setq tmp (get-all-atts a)) (if (> (length tmp) 0) (setq com_data (cons tmp com_data))) );end_for (setq com_data (reverse com_data) tot (length com_data) );end_setq ) );end_cond ;; foreach loop for data display only can be removed later (foreach x com_data (princ x) (princ "\n") );end_foreach (princ) (setvar "osmode" 0) (setq axss nil) (vla-endundomark adoc) );end_defun I have noted that one of the block tags in the example drawing you sent is named "FIND#" not "FIND", which is correct? With regard to the excel part, what do you expect the excel sheet to look like? Is this starting from a pre-define workbook/worksheet or a blank workbook/worksheet? What should the sheet name be? What should the workbook name be. Edited September 18, 2018 by dlanorh Spelling Quote
BIGAL Posted September 19, 2018 Posted September 19, 2018 This is something I am working on but will be looking at a commercial product say Shareware very cheap. Its a modified version of Dataextraction for blocks, you just select relevant blocks, it counts the blocks but uses currently a 2 deep index so will distinguish between the same block name but with different att values eg door black silver v's door black gold wil give 2 totals of the block door with colour and handle type. It makes a table at the moment of the result, I tested on your dwg and it worked. The options are just pick Read a data file re block names and attribute order Likewise create a data file this will be dcl driven for easier picking. The important part is that it supports blocks with as many attributes as in the block I have tested on blocks, 1 att, 2 att, 3 att, 15 att's as a mixture and it works fine. The next step for me is to do the which attributes do you want in the output. Quote
maratovich Posted September 19, 2018 Posted September 19, 2018 (edited) myoujou cain Show us what you want to get in the end. You need to understand what you need. Do you have an example more? Language is not a problem, the main thing is algorithm. Look at this video, like this? https://youtu.be/JTSJD9-VP28 Edited September 19, 2018 by maratovich Quote
myoujou cain Posted September 19, 2018 Author Posted September 19, 2018 (edited) bigal- that's great... I hope to get mine in a form where I can combine it with outside data, similar to the original data extraction. dlanorh- we did do it almost exactly the same except I forgot to remove the constants and I added another condition to eliminate any block where 3 or more of the att's values where nil. its nice to know I'm getting a decent handle on the language. also don't worry about the exact name, I just have to be sure to have the exact name in the "r_lst". everyone- in the end i am hoping to find a way to link it with another spreadsheet, like the original data extraction function can. but what i need is for it to be a CSV file that looks something like this: ("BOM" IS LINKED DATA FROM ANOTHER WORK BOOK) TAG PN BOM FIND QUANTITY SORT CTRL CTRL INFPRO CTRL 1 3000 T-1 T1 CXF460 T1 1 130 also the name of the sheet/workbook wont really matter. this is just a temp file so that the data can be easily uploaded into another program (intuitive). thanks for all your help guys i feel like we are really making progress. Edited September 19, 2018 by myoujou cain Quote
Jim Clayton Posted September 26, 2018 Posted September 26, 2018 I think we're trying to make the same thing. I was able to make quite a bit of progress on it on the Cad side with the help of something RLX sent me. Will post it in the morning. (Sending this now or I'll forget). Quote
BIGAL Posted September 26, 2018 Posted September 26, 2018 I have been renovating my house so no spare time its almost finished about 1 week left so will have time again to get back to "time consuming" ideas. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.