Jump to content

insert blocks and scale from a csv?


chulse

Recommended Posts

Is is possible to programmatically scale blocks based on a field in a CSV or from an attribute?

I have used Lee Mac's Point Manager, (absolutely wonderful programm!!) but do not know how to set each one's scale based on a field in the CSV.

 

Thanks in advance

Link to comment
Share on other sites

Is is possible to programmatically scale blocks based on a field in a CSV or from an attribute?

I have used Lee Mac's Point Manager, (absolutely wonderful programm!!) but do not know how to set each one's scale based on a field in the CSV.

 

Thanks in advance

Csv file should be in the following form:

Block Name,X,Y,Z,Rotation,XScale,YScale

;;demo.lsp
; Convert value in degrees to radians
(defun dtr (a)
 (* pi (/ a 180.0))
) ;_ end of defun
;; by John Unden
(defun ReadCSVFile(FileName / fileh line rtlist)
 (setq fileh (open FileName "r"))
 (while (setq line (read-line fileh))
   (setq rtlist (cons (str2list line ",") rtlist))
   )
 (close fileh)
 (reverse rtlist)
 )
;;;By John Uhden, as posted to the autodesk customization newsgroup 06 Feb 2003
(defun Str2List (str pat / i j n lst)
 (cond
   ((/= (type str)(type pat) 'STR))
   ((= str pat)'(""))
   (T
    (setq i 0 n (strlen pat))
    (while (setq j (vl-string-search pat str i))
      (setq lst (cons (substr str (1+ i)(- j i)) lst)
     i (+ j n)
     )
      )
    (reverse (cons (substr str (1+ i)) lst))
    )
   )
 )
(defun C:demo(/ bname input fname line ;|atdia atreq|; rot
      scale x xscale y yscale z)
 (setq acsp (vla-get-block
       (vla-get-activelayout
  (vla-get-activedocument
    (vlax-get-acad-object)))))
(setq fname (getfiled "Select The Block Data Input File" "" "csv" 0))
(setq input (ReadCSVFile fname))

 (while (setq line (car input))
   (setq bname (nth 0 line)
  x (atof (nth 1 line))
  y (atof (nth 2 line))
  z (atof (nth 3 line))
  rot (dtr (atof (nth 4 line)))
  xscale (atof (nth 5 line))
  yscale (atof (nth 6 line))
  )
   (vlax-invoke-method acsp 'InsertBlock  (vlax-3d-point (list x y z)) bname xscale yscale 1.0 rot)
   (setq input (cdr input))
   )
(princ)
)

 

~'J'~

Link to comment
Share on other sites

Oh good point - my program can only do a blanket insert with all at the same scale...

 

Lee, would it be possibe to add that functionality to you program?

Link to comment
Share on other sites

Csv file should be in the following form:

Block Name,X,Y,Z,Rotation,XScale,YScale

...

 

~'J'~

 

Thanks!

That gives me a great starting place, I need to have it import the block atributes also...

Link to comment
Share on other sites

Lee, would it be possibe to add that functionality to you program?

 

Perhaps - I'm pretty satisfied with the program as it is, so perhaps a custom code would be suitable for your needs in this case.

Link to comment
Share on other sites

Perhaps - I'm pretty satisfied with the program as it is, so perhaps a custom code would be suitable for your needs in this case.

 

custom is perfect :)

 

Is that something you could pull off for me, or at least gve me some hints?

Thanks

Link to comment
Share on other sites

custom is perfect :)

 

Is that something you could pull off for me, or at least gve me some hints?

Thanks

 

Has not Fixo provided sufficient code?

Link to comment
Share on other sites

Has not Fixo provided sufficient code?

 

Unless I am missing it, it wouldn't populate the attributes. Could you point me to a way to add that functionality to it?

Link to comment
Share on other sites

  • 7 years later...

Hi,

 

I know its old thread but found very useful.

 

Could you add attribute vale also for specified blocks. It would be great and will save me tons of time.

I have to insert several blocks on x,y,z with some attributes.

 

thanks :)

 

MK

Link to comment
Share on other sites

Just open the csv with excel and use concatenate to make next line copy the column to the command line and all done.

 

(command "-Insert" bnmame "x,y,z" 1 1 0 att1 att2) etc

Edited by BIGAL
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...