Ampere Posted October 17, 2017 Share Posted October 17, 2017 Hey, I'm new to this forum =) Hoping for some guidance. Is there a way to export dimensions from autoCAD to a txt file? I need the program to get the red dimensions and list them in a txt file. Please be kind, and keep in mind that im completly new to LISP and have very little programing skills outside that but a open mind and willing to learn =) Quote Link to comment Share on other sites More sharing options...
Aftertouch Posted October 17, 2017 Share Posted October 17, 2017 Hello Ampere, This will get you started... (defun C:GetDimLengths ( / AllDimensions CheckDimension n dimlist dimcontent filename fil ) ; Define the command name, localize the variables. (setq AllDimensions (ssget "_X" (list (cons 0 "Dimension")))) ; Sets AllDimensions as a selection set of all Dimensions the the drawing. (setq n 0) ; Set loop counter 0. (setq dimlist '()) ; Set dimensionslist cleared. (repeat (sslength AllDimensions) ; Repeat for all in selectionset AllDimensions (setq CheckDimension (entget (ssname AllDimensions n))) ; Gets the entity (setq dimcontent (cdr (assoc 42 CheckDimension))) ; Reads the measured distance (setq dimlist (cons dimcontent dimlist)) ; Adds this distance to a totallist (setq n (+ 1 n)) ; Up the counter for next dimension ) ; End repeat (if (setq filename (getfiled "\nFile Location..." "DimensionExport" "txt" 11)) ; Make a new textfile with default name (progn ; When created do this. (setq fil (open filename "w")) ; Open the new file (foreach x dimlist ; For all dimensions in the totallist (princ (strcat (rtos x 2) "\n") fil) ; Print them in them in the textfile ) ; Close 'foreach' (close fil) ; Close filewriter (startapp "notepad" filename) ; Open created file with notepad (graphscr) ; Return to screen ) ; Close 'do this' ) ; End if (princ) ; Silent exit ) ; End function - How is the 'red' controlled? ByLayer or set in the propperties? - Needs the list to be sorted? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted October 17, 2017 Share Posted October 17, 2017 Aftertouch, Good efforts. FYI, there is no need to assign an empty list 'dimlist' since the cons function would take care of such a thing. Quote Link to comment Share on other sites More sharing options...
Ampere Posted October 17, 2017 Author Share Posted October 17, 2017 Thanks for the quick reply =D and great with all the comments. The red text is so far only changed in properties but if its easier to extract the values from a layer i can rework the CAD file =) Will try it out tomorrow. Quote Link to comment Share on other sites More sharing options...
Aftertouch Posted October 18, 2017 Share Posted October 18, 2017 change: (setq AllDimensions (ssget "_X" (list (cons 0 "Dimension")))) ; Sets AllDimensions as a selection set of all Dimensions the the drawing. To this, to select all dimensions, where property is set to REd. (setq AllDimensions (ssget "_X" (list (cons 0 "Dimension")(cons 62 1)))) ; Sets AllDimensions as a selection set of all Dimensions the the drawing. or to this, to select all dimensions, when a layername is known (setq AllDimensions (ssget "_X" (list (cons 0 "Dimension")(cons 8 "YOURLAYERNAMEHERE")))) ; Sets AllDimensions as a selection set of all Dimensions the the drawing. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted October 18, 2017 Share Posted October 18, 2017 If you want to pick a dimension and get its layer two methods (setq obj (vlax-ename->vla-object (car (entsel "\nPick Dimension")))) (setq lay (vla-get-layer obj)) (setq AllDimensions (ssget "_X" (list (cons 0 "Dimension")(cons 8 lay)))) (setq obj (entget (car (entsel "\nPick Dimension ")))) (setq lay (cdr (assoc 8 obj))) (setq AllDimensions (ssget "_X" (list (cons 0 "Dimension")(cons 8 lay)))) Quote Link to comment Share on other sites More sharing options...
minhphuong_humg Posted October 24, 2017 Share Posted October 24, 2017 If you want to pick a dimension and get its layer two methods (setq obj (vlax-ename->vla-object (car (entsel "\nPick Dimension")))) (setq lay (vla-get-layer obj)) (setq AllDimensions (ssget "_X" (list (cons 0 "Dimension")(cons 8 lay)))) (setq obj (entget (car (entsel "\nPick Dimension ")))) (setq lay (cdr (assoc 8 obj))) (setq AllDimensions (ssget "_X" (list (cons 0 "Dimension")(cons 8 lay)))) Help me, case Select by Window many dimensions. Thank you. Quote Link to comment Share on other sites More sharing options...
Aftertouch Posted October 24, 2017 Share Posted October 24, 2017 Change the _X to _L Quote Link to comment Share on other sites More sharing options...
minhphuong_humg Posted October 24, 2017 Share Posted October 24, 2017 Dear Aftertouch. Change the _X to _L (defun C:GetDimLengths ( / AllDimensions CheckDimension n dimlist dimcontent filename fil ) ; Define the command name, localize the variables. ;(setq AllDimensions (ssget "_X" (list (cons 0 "Dimension")))) ; Sets AllDimensions as a selection set of all Dimensions the the drawing. (setq obj (vlax-ename->vla-object (car (entsel "\nPick Dimension")))) (setq lay (vla-get-layer obj)) [color="red"][i](setq AllDimensions (ssget "_L" (list (cons 0 "Dimension")(cons 8 lay))))[/i] [/color](setq n 0) ; Set loop counter 0. (setq dimlist '()) ; Set dimensionslist cleared. (repeat (sslength AllDimensions) ; Repeat for all in selectionset AllDimensions (setq CheckDimension (entget (ssname AllDimensions n))) ; Gets the entity (setq dimcontent (cdr (assoc 42 CheckDimension))) ; Reads the measured distance (setq dimlist (cons dimcontent dimlist)) ; Adds this distance to a totallist (setq n (+ 1 n)) ; Up the counter for next dimension ) ; End repeat (if (setq filename (getfiled "\nFile Location..." "DimensionExport" "txt" 11)) ; Make a new textfile with default name (progn ; When created do this. (setq fil (open filename "w")) ; Open the new file (foreach x dimlist ; For all dimensions in the totallist (princ (strcat (rtos x 2) "\n") fil) ; Print them in them in the textfile ) ; Close 'foreach' (close fil) ; Close filewriter (startapp "notepad" filename) ; Open created file with notepad (graphscr) ; Return to screen ) ; Close 'do this' ) ; End if (princ) ; Silent exit ) ; End function I change _X to _L but not working Select (not pick) dimensions. Thanks. Quote Link to comment Share on other sites More sharing options...
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.