
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've tried looking around the forums for similar problems (of which there are a lot), but none of the solutions seem to work for me. I've tried adding the line "(SETQ *DOC* (VLA-GET-ACTIVEDOCUMENT (VLAX-GET-ACAD-OBJECT)))"/"(SETQ *ACTIVEDOC* (VLA-GET-ACTIVEDOCUMENT (VLAX-GET-ACAD-OBJECT)))" among other things to try and fix this error, but nothing seems to work.
Strangely enough, the script worked fine yesterday, and I've tried restarting AutoCAD since, but the problem persists.
The script is supposed to let me click on a closed polyline and generate a text that displays the area in m². As mentioned, the script worked fine yesterday but now only returns the VLA-OBJECT nil error as soon as I try to place the text. In addition to locating what's wrong with the code, I'd like to know if I could improve the script so that I can keep adding text for multiple polylines until I abort the command so that I don't have to input it for each polyline individually.
(DEFUN C:am (/ ACAD-OBJ ADOC AREA AREA-M^2 AREA-TEXT INSERT LWPOLY LWPOLY-OBJ MODEL SELECTIONSETS TEXT-AREAS TEXTSIZE) (VL-LOAD-COM) (SETQ *ACTIVEDOC* (VLA-GET-ACTIVEDOCUMENT (VLAX-GET-ACAD-OBJECT))) (SETQ ACAD-OBJ (VLAX-GET-ACAD-OBJECT)) (SETQ ADOC (VLA-GET-ACTIVEDOCUMENT ACAD-OBJ)) (SETQ MODEL (VLA-GET-MODELSPACE ADOC)) (SETQ SELECTIONSETS (VLA-GET-SELECTIONSETS ADOC)) (VLA-GET-ACTIVESELECTIONSET ADOC) (SETQ LWPOLY (SSGET ":s" '((0 . "LWPOLY*")))) (SETQ LWPOLY-OBJ (VLA-ITEM (VLA-GET-ACTIVESELECTIONSET ADOC) 0)) (SETQ INSERT (GETVAR 'INSUNITS)) (SETVAR 'INSUNITS 4) ; units in mm (SETQ AREA (VLA-GET-AREA LWPOLY-OBJ)) (SETQ AREA-M^2 (RTOS (/ AREA 1000.0 1000.0) 2 2)) (SETQ AREA-TEXT (STRCAT AREA-M^2 " m" "\U+00B2")) (SETQ TEXTSIZE (GETVAR 'DIMTXT)) (SETQ OSMODE (GETVAR 'OSMODE)) (SETVAR 'OSMODE 0) (SETQ TEXT-AREAS (VLA-ADDTEXT MODEL AREA-TEXT (VLAX-3D-POINT (GETPOINT "\ pick place to text")) TEXTSIZE)) (setvar 'OSMODE OSMODE) (VLA-DELETE SS) )
Solved! Go to Solution.