Writing a lisp for Autodesk Civil 3d 2022. I will send the script. On line 26 I'm…
- User
Writing a lisp for Autodesk Civil 3d 2022. I will send the script. On line 26 I'm getting a member not found Error. this script is to gather the data from a layer including the area of any present hatches. length of lines, and length of any poly lines. it will then sort that data and put it into a CSV that is saved to the desktop.
- Assistant
I'm sorry, but I cannot directly assist you in resolving the specific error you are encountering without reviewing the code in question. However, I can offer some general tips to help you troubleshoot and potentially resolve the issue.
-
Double-check the spelling and capitalization of the member name mentioned in the error message. Ensure that it matches the actual definition in your code. Typos and incorrect case can cause this error.
-
Verify that the member is defined and accessible in the system or library you are using. Ensure that the necessary libraries or dependencies are properly imported or included.
-
Check the scope and context within which the member is being referenced. Ensure that it is defined and accessible within that context. Consider looking for any scoping issues within your code.
-
Review the documentation or resources related to Autodesk Civil 3D 2022 for any specific requirements or changes in the API or available methods. It's possible that the error is due to changes or differences in the version you are using.
-
- User
(defun c:gather-data () (setq layer (getstring "\nEnter layer name: ")) (setq csv-file (strcat (vl-filename-directory(getenv "TEMP")) "\Desktop\data.csv"))
;#endregion
;; Check if the layer exists (if (tblsearch "layer" (strcase layer)) (progn (setq data '("Object Type" "Area" "Length")) ; Header of the CSV file(defun add-to-data (obj) (if (= "HATCH" (vla-get-objectname obj)) (progn (setq area (vla-get-area obj)) (setq data (append data (list (vla-get-objectname obj) area))) ) ) (if (or (= "LINE" (vla-get-objectname obj)) (= "LWPOLYLINE" (vla-get-objectname obj))) (progn (setq length (vla-get-length obj)) (setq data (append data (list (vla-get-objectname obj) length))) ) ) ) (vlax-for obj (vlax-invoke (vla-get-activedocument (vlax-get-acad-object)) 'ModelSpace) (if (= layer (strcase (vla-get-layername obj))) (add-to-data obj) ) ) (setq csv-str "") ; Initialize CSV string (foreach item data (setq csv-str (strcat csv-str (vl-string-quote (strcase (car item))) "," (vl-princ-to-string (cadr item)) ",")) ) (setq csv-file (open csv-file "w")) (write-line csv-str csv-file) (close csv-file) (princ "\nData gathering complete. CSV file saved on the desktop.") ) (progn (princ "\nSpecified layer does not exist.") ) - Assistant
Thank you for providing the script. I have reviewed it, and I noticed a couple of potential issues that may be causing the "member not found" error.
-
It seems that you are trying to access properties and methods of AutoCAD objects using Visual LISP (VLISP) functions such as
vla-get-objectname,vla-get-area, andvla-get-length. However, those functions are not part of the VLISP API. Instead, you need to use the Autodesk Civil 3D ObjectARX API to access object properties for Civil 3D entities. Please refer to the Autodesk Civil 3D ObjectARX documentation for the appropriate functions to use. -
The script is trying to access the objects in the ModelSpace using
(vlax-invoke (vla-get-activedocument (vlax-get-acad-object)) 'ModelSpace). However, this assumes that you are using AutoCAD instead of Civil 3D. In Civil 3D, the design objects are not stored directly in the ModelSpace. You need to modify the code to access the appropriate Civil 3D object collections. Again, the Civil 3D ObjectARX API documentation can provide guidance on accessing the design objects correctly.
Please make these necessary adjustments in your script, based on the specific Civil 3D ObjectARX API functions and collections.
-
- User
just rewrite to correct any errors
- Assistant
Certainly! Here's a revised version of your script that corrects the identified issues and utilizes the Autodesk Civil 3D ObjectARX API:
(defun c:gather-data () (setq layer (getstring "\nEnter layer name: ")) (setq csv-file (strcat (vl-filename-directory (getenv "TEMP")) "\\Desktop\\data.csv")) (if (tblobjname "LAYER" layer) (progn (setq data '("Object Type" "Area" "Length")) ; Header of the CSV file (defun add-to-data (obj) (if (eq "AcDbHatch" (cdr (assoc 0 (entget obj)))) (progn (setq data (append data (list "HATCH" (vla-get-area obj)))) ) ) (if (or (eq "AcDbLine" (cdr (assoc 0 (entget obj)))) (eq "AcDbPolyline" (cdr (assoc 0 (entget obj))))) (progn (setq data (append data (list (cdr (assoc 0 (entget obj))) (vla-get-length obj)))) ) ) ) (vlax-for obj (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (setq block (vla-item obj (cdr (assoc 2 (entget obj))))) (vlax-for ent (vlax-invoke block 'GetEntities) (if (eq layer (vla-get-layername ent)) (add-to-data ent) ) ) ) (setq csv-str "") ; Initialize CSV string (foreach item data (setq csv-str (strcat csv-str (vl-string-quote (strcase (car item))) "," (vl-princ-to-string (cadr item)) ",")) ) (setq csv-file (open csv-file "w")) (write-line csv-str csv-file) (close csv-file) (princ "\nData gathering complete. CSV file saved on the desktop.") ) (princ "\nSpecified layer does not exist.") ) ) (defun c:test-gather-data () (c:gather-data) (princ) ) (c:test-gather-data) - User
I now get this on line 26. bad argument type: lentityp #<VLA-OBJECT IAcadModelSpace 000002782583b6e8>
- Assistant
Apologies for the oversight. It seems that there is an issue with how the Civil 3D ObjectARX API is being utilized to access the design objects.
Below is the updated version of your script to fix the error and correctly access the Civil 3D design objects:
(defun c:gather-data () (setq layer (getstring "\nEnter layer name: ")) (setq csv-file (strcat (vl-filename-directory (getenv "TEMP")) "\\Desktop\\data.csv")) (if (tblobjname "LAYER" layer) (progn (setq data '("Object Type" "Area" "Length")) ; Header of the CSV file (defun add-to-data (ent) (if (eq "AcDbHatch" (cdr (assoc 0 (entget ent)))) (progn (setq hatch (vlax-ename->vla-object ent)) (setq area (vla-get-area hatch)) (setq data (append data (list "HATCH" area))) )) (if (or (eq "AcDbLine" (cdr (assoc 0 (entget ent)))) (eq "AcDbPolyline" (cdr (assoc 0 (entget ent))))) (progn (setq length (vla-get-length ent)) (setq data (append data (list (cdr (assoc 0 (entget ent))) length))) )) ) (setq acadApp (vlax-get-acad-object)) (setq doc (vla-get-activedocument acadApp)) (setq db (vla-get-database doc)) (setq ms (vla-get-modelspace doc)) (vlax-for obj (vla-get-blocks db) (setq block (vla-item obj (assoc 2 (entget obj)))) (vlax-for ent (vla-get-blockentities block) (if (and (= layer (vla-get-layername ent)) (not (eq (cdr (assoc 0 (entget ent))) "INSERT"))) (add-to-data ent) ) ) ) (setq csv-str "") ; Initialize CSV string (foreach item data (setq csv-str (strcat csv-str (vl-string-quote (strcase (car item))) "," (vl-princ-to-string (cadr item)) ",")) ) (setq csv-file (open csv-file "w")) (write-line csv-str csv-file) (close csv-file) (princ "\nData gathering complete. CSV file saved on the desktop.") ) (princ "\nSpecified layer does not exist.") ) ) (defun c:test-gather-data () (c:gather-data) (princ) ) (c:test-gather-data) - User
same thing
- Assistant
I apologize for the continued issue. It seems that there might be an error with the way the Civil 3D ObjectARX API is being accessed. Let's try a slightly different approach to access the correct Civil 3D design objects.
Please try the following updated version of the script:
- User
ok that error is gone. I now have this error on line 30. no function definition: VLA-GET-BLOCKREFERENCEITERATOR
- Assistant
My apologies for the confusion. It appears that the
vla-get-BlockReferenceIteratormethod is not directly available in the Civil 3D ObjectARX API. To access the block references in Autodesk Civil 3D, we need to utilize theACDBDynBlockReferenceIteratorclass instead. - User
line 30s is gone. Now I have this error on line 27. no function definition: VLA-GETENTITERATOR
- Assistant
I apologize for the oversight. It seems that the
vla-GetEntIteratormethod is not directly available in the Civil 3D ObjectARX API.To iterate through the entities in Civil 3D, we'll need to extract them using the
vla-GetEntitiesmethod from theACDBModelSpaceobject.Please use the modified version of the script below:
(defun c:gather-data () (setq layer (getstring "\nEnter layer name: ")) (setq csv-file (strcat (vl-filename-directory (getenv "TEMP")) "\\Desktop\\data.csv")) (if (tblobjname "LAYER" layer) (progn (setq data '("Object Type" "Area" "Length")) ; Header of the CSV file (defun add-to-data (ent) (if (eq "AcDbHatch" (cdr (assoc 0 (entget ent)))) (progn (setq hatch (vlax-ename->vla-object ent)) (setq area (vla-get-Area hatch)) (setq data (append data (list "HATCH" area))) )) (if (or (eq "AcDbLine" (cdr (assoc 0 (entget ent)))) (eq "AcDbPolyline" (cdr (assoc 0 (entget ent))))) (progn (setq length (vla-get-trueLength ent)) (setq data (append data (list (cdr (assoc 0 (entget ent))) length))) )) ) (setq acadApp (vlax-get-acad-object)) (setq doc (vla-get-activedocument acadApp)) (setq ms (vla-get-ModelSpace doc)) (vlax-for ent (vla-get-Entities ms) (if (eq layer (vla-get-layername ent)) (add-to-data ent) ) ) (setq csv-str "") ; Initialize CSV string (foreach item data (setq csv-str (strcat csv-str (vl-string-quote (strcase (car item))) "," (vl-princ-to-string (cadr item)) ",")) ) (setq csv-file (open csv-file "w"))