Author Topic: Get Properties of non-uniformly scalled blocks  (Read 6382 times)

0 Members and 1 Guest are viewing this topic.

artisteroi

  • Guest
Get Properties of non-uniformly scalled blocks
« on: June 24, 2010, 10:25:32 AM »
HI,

I need a routine that can get the properties from a group of non-uniformly scaled blocks and write the data into a csv file.

First I need 2 user questions "Specify Part ID" and "Specify Factory ID"
Then I need the Block Name, Position X, Position Y, Position Z, also the Scale X, Scale Y, Scale Z.  lastly I need the layer name. It needs to do multiple blocks all at once, by selecting teh whole group. Could be as many as 100+ blocks at once.

Then write the whole thing to a CSV file.

Anyone want to give me a hand? My lisp skills are poor when it comes to data extraction. But if you need some help with lisp that does animation or draws in model space I can help with that.

Attached is a sample file and a csv to write to. Any help would be appreciated.

fixo

  • Guest
Re: Get Properties of non-uniformly scalled blocks
« Reply #1 on: June 24, 2010, 01:24:59 PM »
Start with this one
(I don't know where you stored Part and Factory for blocks) :wink:

Code: [Select]
(vl-load-com)
;;==============================================;;

(defun C:BCSV (/ *error* datafile data_line en filename obj sset)

  (defun *error* (msg)
    (if datafile (close datafile))
    (if msg (princ (strcat "\nError! " msg)))
    (princ)
    )
 
(setq filename (strcat (getvar "dwgprefix")
      (vl-filename-base (getvar "dwgname"))".csv")
)

  (command "._zoom" "_e")
  (if
    (setq sset (ssget "X" (list (cons 0 "INSERT")(cons 410 (getvar "CTAB")))))
     (progn
       (setq datafile (open filename "W"))
       (setq data_line "Part,Factory,Block Name,Position X,Position Y,Position Z,Scale X,Scale Y,Scale Z,Layer Name")
        (write-line data_line datafile)

       (while (setq en (ssname sset 0))
       (setq obj (vlax-ename->vla-object en))
  (setq data_line (strcat "KnownPart" ","
  "KnownFactory" ","
  (vlax-get-property obj 'EffectiveName) ","
  (rtos (car (vlax-get obj 'InsertionPoint)) 2 3) ","
  (rtos (cadr (vlax-get obj 'InsertionPoint)) 2 3) ","
  (rtos (caddr (vlax-get obj 'InsertionPoint)) 2 3) ","
  (rtos (vlax-get-property obj 'XScaleFactor) 2 1) ","
  (rtos (vlax-get-property obj 'YScaleFactor) 2 1) ","
  (rtos (vlax-get-property obj 'ZScaleFactor) 2 1) ","
  (vla-get-layer obj)))
 
  (write-line data_line datafile)
  (ssdel en sset)
  )
       
       (close datafile)

       )
     )
(command "._zoom" "_p")
  (princ)
  )
   
(prompt "\nStart command with BCSV")
(prin1)

~'J'~

artisteroi

  • Guest
Re: Get Properties of non-uniformly scalled blocks
« Reply #2 on: June 24, 2010, 01:58:01 PM »
Hey Oleg,

It's becoming quite a habit you saving my neck with your code :)

This is close, but I need the user to put in the info for "known part" and "Known Factory". Then it has to append to the csv file so I can do it many times over. I would modify the code you left here myself if I had the skills.

fixo

  • Guest
Re: Get Properties of non-uniformly scalled blocks
« Reply #3 on: June 24, 2010, 02:15:30 PM »
Hey Oleg,

It's becoming quite a habit you saving my neck with your code :)

This is close, but I need the user to put in the info for "known part" and "Known Factory". Then it has to append to the csv file so I can do it many times over. I would modify the code you left here myself if I had the skills.

Huh, if you have a thousand of blocks do you say that your
users should be always put 'Part' and 'Factory' for every separate block
or these things is common for whole heap of blocks???
Sorry, I don't understand again  :oops:

~'J'~

fixo

  • Guest
Re: Get Properties of non-uniformly scalled blocks
« Reply #4 on: June 24, 2010, 02:30:21 PM »
Hey Oleg,

It's becoming quite a habit you saving my neck with your code :)

This is close, but I need the user to put in the info for "known part" and "Known Factory". Then it has to append to the csv file so I can do it many times over. I would modify the code you left here myself if I had the skills.

Here is another one I thought it will be better
Code: [Select]

(vl-load-com)
;;==============================================;;

(defun C:BCSV (/ *error* datafile data_line en filename obj sset)

  (defun *error* (msg)
    (if datafile (close datafile))
    (if msg (princ (strcat "\nError! " msg)))
    (princ)
    )
 
(setq filename (strcat (getvar "dwgprefix")
      (vl-filename-base (getvar "dwgname"))".csv")
)

  (command "._zoom" "_e")
  (if
    (setq sset (ssget "X" (list (cons 0 "INSERT")(cons 410 (getvar "CTAB")))))
     (progn
       (setq part (getstring T "\nReference Part: "))
       (setq fact (getstring T "\nReference : "))
       (setq datafile (open filename "W"))
       (setq data_line "Part,Factory,Block Name,Position X,Position Y,Position Z,Scale X,Scale Y,Scale Z,Layer Name")
        (write-line data_line datafile)

       (while (setq en (ssname sset 0))
       (setq obj (vlax-ename->vla-object en))
  (setq data_line (strcat part ","
  fact ","
  (vlax-get-property obj 'EffectiveName) ","
  (rtos (car (vlax-get obj 'InsertionPoint)) 2 3) ","
  (rtos (cadr (vlax-get obj 'InsertionPoint)) 2 3) ","
  (rtos (caddr (vlax-get obj 'InsertionPoint)) 2 3) ","
  (rtos (vlax-get-property obj 'XScaleFactor) 2 1) ","
  (rtos (vlax-get-property obj 'YScaleFactor) 2 1) ","
  (rtos (vlax-get-property obj 'ZScaleFactor) 2 1) ","
  (vla-get-layer obj)))
 
  (write-line data_line datafile)
  (ssdel en sset)
  )
       
       (close datafile)

       )
     )
(command "._zoom" "_p")
  (princ)
  )
   
(prompt "\nStart command with BCSV")
(prin1)

artisteroi

  • Guest
Re: Get Properties of non-uniformly scalled blocks
« Reply #5 on: June 24, 2010, 02:32:41 PM »
if there are a thousand blocks they all have the same part id number. The user selects the whole lot of them and the csv shows 1000 entries all with the same part id and factory id. So the whole selection set will only ask the 2 questions first then select all 1000 blocks.

fixo

  • Guest
Re: Get Properties of non-uniformly scalled blocks
« Reply #6 on: June 24, 2010, 02:35:31 PM »
if there are a thousand blocks they all have the same part id number. The user selects the whole lot of them and the csv shows 1000 entries all with the same part id and factory id. So the whole selection set will only ask the 2 questions first then select all 1000 blocks.

Try last edited code :)

~'J'~

artisteroi

  • Guest
Re: Get Properties of non-uniformly scalled blocks
« Reply #7 on: June 24, 2010, 02:45:55 PM »
that last code works good.

I tried to past in some code to make it append top the csv file but I failed. Can you make it append?

fixo

  • Guest
Re: Get Properties of non-uniformly scalled blocks
« Reply #8 on: June 24, 2010, 02:56:45 PM »
Change these lines
Code: [Select]
       (setq datafile (open filename "W"))
       (setq data_line "Part,Factory,Block Name,Position X,Position Y,Position Z,Scale X,Scale Y,Scale Z,Layer Name")
        (write-line data_line datafile)

on this one:
Code: [Select]
  (setq datafile (open filename [color=red]"A"[/color]))
~'J'~

artisteroi

  • Guest
Re: Get Properties of non-uniformly scalled blocks
« Reply #9 on: June 24, 2010, 03:03:12 PM »
close enough I guess. It writes the header again as it appends the data, but i guess i can delete that out of the file afterward. beggars can't be choosers after all.
Thanks for teh help Oleg. Now I ow you 2 beers. :)

fixo

  • Guest
Re: Get Properties of non-uniformly scalled blocks
« Reply #10 on: June 24, 2010, 03:10:55 PM »
Hey, I already drink a beer
Holland vs.Camerron 1:0 yet  :)

Try edited:

Code: [Select]
(vl-load-com)
;;==============================================;;

(defun C:BCSV (/ *error* datafile data_line en filename obj sset)

  (defun *error* (msg)
    (if datafile (close datafile))
    (if msg (princ (strcat "\nError! " msg)))
    (princ)
    )
 
(setq filename (strcat (getvar "dwgprefix")
      (vl-filename-base (getvar "dwgname"))".csv")
)

  (command "._zoom" "_e")
  (if
    (setq sset (ssget "X" (list (cons 0 "INSERT")(cons 410 (getvar "CTAB")))))
     (progn
       (setq part (getstring T "\nReference Part: "))
       (setq fact (getstring T "\nReference : "))
       (setq datafile (open filename "A"))
       

       (while (setq en (ssname sset 0))
       (setq obj (vlax-ename->vla-object en))
  (setq data_line (strcat part ","
  fact ","
  (vlax-get-property obj 'EffectiveName) ","
  (rtos (car (vlax-get obj 'InsertionPoint)) 2 3) ","
  (rtos (cadr (vlax-get obj 'InsertionPoint)) 2 3) ","
  (rtos (caddr (vlax-get obj 'InsertionPoint)) 2 3) ","
  (rtos (vlax-get-property obj 'XScaleFactor) 2 1) ","
  (rtos (vlax-get-property obj 'YScaleFactor) 2 1) ","
  (rtos (vlax-get-property obj 'ZScaleFactor) 2 1) ","
  (vla-get-layer obj)))
 
  (write-line data_line datafile)
  (ssdel en sset)
  )
       
       (close datafile)

       )
     )
(command "._zoom" "_p")
  (princ)
  )
   
(prompt "\nStart command with BCSV")
(prin1)

artisteroi

  • Guest
Re: Get Properties of non-uniformly scalled blocks
« Reply #11 on: June 24, 2010, 03:50:52 PM »
that worked perfectly. I wish I could figure this stuff out myself, but I just can't understand what the code is doing.

fixo

  • Guest
Re: Get Properties of non-uniformly scalled blocks
« Reply #12 on: June 24, 2010, 05:13:17 PM »
Sorry, I can't explain you things enough
Btw, why lisp, you used C# earlier as I remember it..
Here is the same eggs but on C#
Remove unused references from 'using' region

~'J'~

artisteroi

  • Guest
Re: Get Properties of non-uniformly scalled blocks
« Reply #13 on: June 24, 2010, 05:18:49 PM »
I choose Lisp when I am the user. When our head programmer is the user she wants c#. Also I keep telling myself that I can modify the lisp if need be but it never happens.

I wish we were not so short handed here then I wouldn't need to mess with code at all I could just do the engineering. Maybe some day we will be able to hire a few staff members again.

fixo

  • Guest
Re: Get Properties of non-uniformly scalled blocks
« Reply #14 on: June 24, 2010, 05:38:24 PM »
No problem,

Keep in touch :-)

~'J'~

artisteroi

  • Guest
Re: Get Properties of non-uniformly scalled blocks
« Reply #15 on: July 01, 2010, 11:04:47 AM »
Oleg,
Would you want to make a small adjustment to this code for me? The output file only has 1 decimal place in the cells. can that be changed to 4 decimal places. I tried to do it myself but couldn't figure it out. Any help would be appreciated. Below is the one I am using.

Code: [Select]
(vl-load-com)
;;==============================================;;

(defun C:BCSV (/ *error* datafile data_line en filename obj sset)

  (defun *error* (msg)
    (if datafile (close datafile))
    (if msg (princ (strcat "\nError! " msg)))
    (princ)
    )
 
(setq filename (strcat (getvar "dwgprefix")
      (vl-filename-base (getvar "dwgname"))".csv")
)

  (command "._zoom" "_e")
  (if
    (setq sset (ssget "X" (list (cons 0 "INSERT")(cons 410 (getvar "CTAB")))))
     (progn
       (setq part (getstring T "\nProduct Code: "))
       (setq fact (getstring T "\nManufacturer : "))
       (setq datafile (open filename "A"))
       

       (while (setq en (ssname sset 0))
       (setq obj (vlax-ename->vla-object en))
  (setq data_line (strcat part ","
  fact ","
  (vlax-get-property obj 'EffectiveName) ","
  (rtos (car (vlax-get obj 'InsertionPoint)) 2 3) ","
  (rtos (cadr (vlax-get obj 'InsertionPoint)) 2 3) ","
  (rtos (caddr (vlax-get obj 'InsertionPoint)) 2 3) ","
  (rtos (vlax-get-property obj 'XScaleFactor) 2 1) ","
  (rtos (vlax-get-property obj 'YScaleFactor) 2 1) ","
  (rtos (vlax-get-property obj 'ZScaleFactor) 2 1) ","
  (vla-get-layer obj)))
 
  (write-line data_line datafile)
  (ssdel en sset)
  )
       
       (close datafile)

       )
     )
(command "._zoom" "_p")
  (princ)
  )
   
(prompt "\nStart command with BCSV")
(prin1)
 

artisteroi

  • Guest
Re: Get Properties of non-uniformly scalled blocks
« Reply #16 on: July 01, 2010, 04:36:25 PM »
never mind I figured it out. (WOO HOO)

Code: [Select]
  (rtos (car (vlax-get obj 'InsertionPoint)) 2 3) ","
  (rtos (cadr (vlax-get obj 'InsertionPoint)) 2 3) ","
  (rtos (caddr (vlax-get obj 'InsertionPoint)) 2 3) ","
  (rtos (vlax-get-property obj 'XScaleFactor) 2 1) ","
  (rtos (vlax-get-property obj 'YScaleFactor) 2 1) ","
  (rtos (vlax-get-property obj 'ZScaleFactor) 2 1) ","

the last set of digits in these lines control the decimal places. I changed the 3 and ones to 4. works fine now

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Get Properties of non-uniformly scalled blocks
« Reply #17 on: July 01, 2010, 04:40:17 PM »
Watch out for the the effective scale factor.

Code: [Select]
;   XEffectiveScaleFactor = 1.0
;   XScaleFactor = 1.0
;   YEffectiveScaleFactor = 1.0
;   YScaleFactor = 1.0
;   ZEffectiveScaleFactor = 1.0
;   ZScaleFactor = 1.0
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

artisteroi

  • Guest
Re: Get Properties of non-uniformly scalled blocks
« Reply #18 on: July 01, 2010, 04:42:44 PM »
ahhh! dont confuse me!

It's working, thats all that counts