cjc_cristian Posted December 11 Posted December 11 (edited) Hello, I'm working on a lisp that gets me data from a civil 3d alignment, data such as the name of the alignment and the staking at a point indicated by the user, everything works fine except when I use a method as follows to find said staking: (vlax-invoke-method objAlign 'StationOffset (vlax-3D-point point)), there civil generates an error indicating that the real parameters are insufficient, could someone help me please? (defun c:vf ( / ent objAlign alignName point station) ;; Cargar el soporte de ActiveX (vl-load-com) ;; Solicitar al usuario que seleccione una entidad (prompt "\nSelecciona un alineamiento: ") (setq ent (entsel)) ; Seleccionar la entidad ;; Verificar si se seleccionó una entidad (if ent (progn ;; Convertir la entidad en objeto ActiveX (setq objAlign (vlax-ename->vla-object (car ent))) ;; Verificar si es un alineamiento (if (and (vlax-property-available-p objAlign 'ObjectName) (eq (vla-get-ObjectName objAlign) "AeccDbAlignment")) (progn ;; Obtener el nombre del alineamiento (setq alignName (vla-get-Name objAlign)) ;; Solicitar al usuario un punto en pantalla (prompt "\nHaz clic en un punto sobre el alineamiento: ") (setq point (getpoint)) ; Capturar el punto seleccionado por el usuario ;; Calcular el estacado en el punto seleccionado (setq station (vlax-invoke-method objAlign 'StationOffset (vlax-3D-point point))) ;; Mostrar el nombre del alineamiento y la longitud en el punto clicado (prompt (strcat "\nEl alineamiento seleccionado es: " alignName)) (prompt (strcat "\nEl estacado en el punto seleccionado es: " (rtos (car station) 2 2) " unidades.")) ) ;; No es un alineamiento (prompt "\nLa entidad seleccionada no es un alineamiento.") ) ) ;; No se seleccionó ninguna entidad (prompt "\nNo se seleccionó ninguna entidad.") ) (princ) ) Edited December 11 by SLW210 Added Code Tags!! Quote
SLW210 Posted December 11 Posted December 11 Please use Code Tags for your code in the future. (<> in the editor toolbar) 1 Quote
Lee Mac Posted December 11 Posted December 11 From the documentation, the StationOffset method will accept an X & Y coordinate and return two output parameters (station & offset), as such, you'll need to supply the appropriate number of parameters, e.g.: (vlax-invoke-method objAlign 'StationOffset (car point) (cadr point) 'stn 'off) (print stn) (prin1 off) 2 Quote
cjc_cristian Posted December 12 Author Posted December 12 I understand SLW210, I'll take it into account, thanks. I see Lee Mac, thanks for your insight, but I still don't understand what is related to the 'stn' and 'off variables, please help me with that Quote
cjc_cristian Posted December 12 Author Posted December 12 (edited) Thanks Lee Mac, now it works perfectly, I share the corrected code (defun c:CheckA ( / ent objAlign alignName point x y stn off) ;; Cargar el soporte de ActiveX (vl-load-com) ;; Solicitar al usuario que seleccione una entidad (prompt "\nSelecciona un alineamiento: ") (setq ent (entsel)) ; Seleccionar la entidad ;; Validar si se seleccionó una entidad (if (and ent (car ent)) (progn ;; Intentar convertir la entidad en un objeto ActiveX (setq objAlign (vlax-ename->vla-object (car ent))) ;; Validar si la entidad seleccionada es un alineamiento (if (and objAlign (eq (vla-get-ObjectName objAlign) "AeccDbAlignment")) (progn ;; Obtener el nombre del alineamiento (setq alignName (vla-get-Name objAlign)) ;; Solicitar al usuario un punto en pantalla (prompt "\nHaz clic en un punto sobre el alineamiento: ") (setq point (getpoint)) ; Capturar el punto seleccionado por el usuario ;; Descomponer el punto en coordenadas X e Y (setq x (car point) y (cadr point)) ;; Inicializar las variables de salida para el estacado y el offset (setq stn 0.0 off 0.0) ; Inicializar valores de salida ;; Llamar al método StationOffset (vlax-invoke-method objAlign 'StationOffset x y 'stn 'off) ;; Mostrar los resultados al usuario (prompt (strcat "\nEl alineamiento seleccionado es: " alignName)) (prompt (strcat "\nEl estacado en el punto seleccionado es: " (rtos stn 2 2) " unidades.")) (prompt (strcat "\nEl offset en el punto seleccionado es: " (rtos off 2 2) " unidades.")) ) ;; No es un alineamiento (prompt "\nLa entidad seleccionada no es un alineamiento.") ) ) ;; No se seleccionó ninguna entidad (prompt "\nNo se seleccionó ninguna entidad.") ) (princ) ; Finalizar silenciosamente ) Edited December 12 by cjc_cristian Quote
Lee Mac Posted December 12 Posted December 12 You're welcome - though, note that there's no need to initialise the two output variables as LISP is not strongly typed. 1 Quote
cjc_cristian Posted December 14 Author Posted December 14 Excuse me now I want to improve the previous code, where this value of the station of a point chopped on an alignment, I want to add it as a label of a cogo point style that I have preset, is it possible? How could I do it, any idea, I would be very grateful and happy if you could make this link from civil to lisp please Quote
cjc_cristian Posted December 14 Author Posted December 14 In short, I need to insert into the label of a civil cog point the value of the progressive or station that I have already managed to extract with the previous algorithm, so that it appears as in the attached image. Quote
hosneyalaa Posted December 14 Posted December 14 Extract Station value to Excel for each point and then add it as a description of a point Quote
cjc_cristian Posted December 14 Author Posted December 14 Of course, exporting and then importing the point with this attribute from Excel is possible, but what I need is to do it with a Lisp that automatically inserts the value of this label into the properties of the chopped point, for which I do not have the function or method that helps me do it. Quote
BIGAL Posted December 14 Posted December 14 Inside CIV3D directory is a sub directory, trying to remember I think it was called API, in that are VBA and lisp example code, one of the examples is make cogo points, so you could add your points. I found these need the two joined into 1. This needs to be crossed checked for variable names I have changed over the years. ; vercheck.lsp version check for *aecc objects ; uses registerycheck (defun ah:vercheck ( / vrsn appstr) (vl-load-com) (setq acApp (vlax-get-acad-object)) (setq C3D (strcat "HKEY_LOCAL_MACHINE\\" (if vlax-user-product-key (vlax-user-product-key) (vlax-product-key) ) ) C3D (vl-registry-read C3D "Release") C3D (substr C3D 1 (vl-string-search "." C3D (+ (vl-string-search "." C3D) 1)) ) ) (setq *AeccDoc*(vla-getinterfaceobject (vlax-get-acad-object) (strcat "AeccXUiLand.AeccApplication." C3D) ) ) (setq aeccDoc (vlax-get-property *aeccdoc* "ActiveDocument")) (princ) ) An alternative I have lost the 2021+ I am sure others have the values. ;vercheck.lsp version check for *aecc objects ; By Alan H (defun ah:vercheck ( / vrsn appstr) (vl-load-com) (if ((lambda (vrsn) (cond ((vl-string-search "R17.2" vrsn) (setq appstr "6.0")) ;09 ((vl-string-search "R18.0" vrsn) (setq appstr "7.0")) ;2010 ((vl-string-search "R18.1" vrsn) (setq appstr "8.0")) ;2011 ((vl-string-search "R18.2" vrsn) (setq appstr "9.0")) ;2012 ((vl-string-search "R19.0" vrsn) (setq appstr "10.0")) ;2013 ((vl-string-search "R19.1" vrsn)(setq appstr "10.3"));;2014 ((vl-string-search "R20.0" vrsn)(setq appstr "10.4"));;2015 ((vl-string-search "R20.1" vrsn)(setq appstr "10.5"));;2016 ((vl-string-search "R21.0" vrsn)(setq appstr "11.0"));;2017 ((vl-string-search "R22.0" vrsn)(setq appstr "12.0"));;2018 ((vl-string-search "R23.0" vrsn)(setq appstr "13.0"));;2019 ((vl-string-search "R23.1" vrsn)(setq appstr "13.2"));;2020 ((alert "This version of C3D not supported!")) ) ) (vlax-product-key) ) ; end if condition progn is true (progn (cond (*AeccDoc*) ((setq *AeccDoc* (vlax-get (cond (*AeccApp*) ((setq *AeccApp* (vla-getinterfaceobject (cond (*Acad*) ((setq *Acad* (vlax-get-acad-object))) ) (strcat "AeccXUiLand.AeccApplication." appstr) ) ) ) ) 'ActiveDocument ) ) ) ) ; end main cond ) ; end progn ) ; end if vsrn CIV3D point edit desc.lsp CIV3D create point.lsp Quote
alanjt Posted December 20 Posted December 20 On 12/14/2024 at 12:05 AM, cjc_cristian said: In short, I need to insert into the label of a civil cog point the value of the progressive or station that I have already managed to extract with the previous algorithm, so that it appears as in the attached image. Why wouldn't you just use an alignment station offset label? Quote
BIGAL Posted Friday at 10:59 PM Posted Friday at 10:59 PM Hi @alanjt I think that is what he is trying to do but he has a POINT not a cogo point so need a make a point. Found this thought I had something. ; create civ3d points example ; By Alan H 2019 (vl-load-com) (if (not AH:vercheck)(load "vercheck")) (ah:vercheck) (setq *aeccDoc* (vlax-get-property *aeccApp* "ActiveDocument")) (setq oPoints (vlax-get-property *aeccDoc* "Points")) (setq pt1 (vlax-3d-point '(10.0 10.0 1.0))) (setq oPoint1 (vlax-invoke-method oPoints "Add" pt1)) (vlax-put opoint1 'labelrotation (/ pi 2.0)) ;90deg (setq pt1 (vlax-3d-point '(20.0 10.0 2.0))) (setq oPoint1 (vlax-invoke-method oPoints "Add" pt1)) (vlax-put opoint1 'labelrotation 3.14) ;approx 180deg (setq pt1 (vlax-3d-point '(20.0 20.0 3.0))) (setq oPoint1 (vlax-invoke-method oPoints "Add" pt1)) (vlax-put opoint1 'labelrotation 4.71) ;approx 270deg ; to do all to an angle ;(vlax-for Point (vlax-get-property *aeccDoc* "Points") ; (vlax-put point 'labelrotation 1.57) ;approx 90deg ;) (princ) CIV3D change point style.lsp Quote
cjc_cristian Posted Saturday at 03:41 PM Author Posted Saturday at 03:41 PM (edited) Hi @alanjt and @Grande, I think I didn’t explain myself clearly in my previous message, so I’d like to clarify my situation: Currently, I have predefined COGO points in Civil 3D with a custom style to which I’ve added an extra label called “progresivaa”. This label appears in the point’s presentation and has a unique value for each point, which I’ve been editing manually so far. A few days ago, I managed to program a Lisp that retrieves this value. Now, I want to take it a step further: I’m looking for an algorithm or Lisp code that allows me to automatically edit or add these values to the “progresivaa” label for each selected COGO point. I would greatly appreciate any guidance, code examples, or ideas you can share to help me achieve this goal. Thank you in advance for your assistance! Edited Saturday at 03:44 PM by cjc_cristian Quote
BIGAL Posted Saturday at 10:43 PM Posted Saturday at 10:43 PM Did you look at my make cogo point ? You should be able to use that to make the cogo point, with correct description. Not sure about a chainage along the alignment you may be able to do in the label style, no CIV3D at moment. Else need to get distance along alignment, you can get start chainage from an alignment using lisp. Quote
alanjt Posted Sunday at 07:56 PM Posted Sunday at 07:56 PM (edited) Look at SetUserDefinedPropertyValue and GetUserDefinedPropertyValue. Here's an example one I wrote a while back. (defun c:PSOP (/ align name ss i o sta off) ;; Add Station and Offset of Selected Alignment to Selected Points ;; Alan J. Thompson, 2021.10.12 (cond ((not (AT:GetSel entsel "\nSelect reference alignment: " (lambda (x) (if (eq (cdr (assoc 0 (entget (car x)))) "AECC_ALIGNMENT") (setq align (vlax-ename->vla-object (car x))) ) ) ) ) ) ((not (progn (princ (strcat "\nSelect C3D points to associate with selected \"" (setq name (vlax-get align 'Name)) "\" alignment: " ) ) (setq ss (ssget '((0 . "AECC_COGO_POINT")))) ) ) ) (T (repeat (setq i (sslength ss)) (setq o (vlax-ename->vla-object (ssname ss (setq i (1- i)))) sta nil off nil ) (vlax-invoke-method align 'StationOffset (vlax-get o 'Easting) (vlax-get o 'Northing) 'sta 'off) (if (and sta off) (progn (vl-catch-all-apply 'vlax-invoke (list o 'SetUserDefinedPropertyValue "Station" sta)) (vl-catch-all-apply 'vlax-invoke (list o 'SetUserDefinedPropertyValue "Station Offset" off)) (vl-catch-all-apply 'vlax-invoke (list o 'SetUserDefinedPropertyValue "Alignment Name" name)) ) ) ) ) ) (princ) ) (vl-load-com) (princ) (defun AT:GetSel (meth msg fnc / ent) ;; meth - selection method (entsel, nentsel, nentselp) ;; msg - message to display (nil for default) ;; fnc - optional function to apply to selected object ;; Ex: (AT:GetSel entsel "\nSelect arc: " (lambda (x) (eq (cdr (assoc 0 (entget (car x)))) "ARC"))) ;; Alan J. Thompson, 05.25.10 (while (progn (setvar 'ERRNO 0) (setq ent (meth (cond (msg) ("\nSelect object: ") ) ) ) (cond ((eq (getvar 'ERRNO) 7) (princ "\nMissed, try again.")) ((eq (type (car ent)) 'ENAME) (if (and fnc (not (fnc ent))) (princ "\nInvalid object!") ) ) ) ) ) ent ) Edited Monday at 03:06 PM by alanjt Quote
cjc_cristian Posted Sunday at 10:50 PM Author Posted Sunday at 10:50 PM (edited) Yes Bigal, I have reviewed it! However, I found some issues with the code, especially in the line (setq oPoints (vlax-get-property *aeccDoc* "Points")), which gives me an error. Nevertheless, I want to thank you for the attention and for the shared codes. Finally, I was able to solve my problem by storing the progressive data in a native property of the COGO point, which allowed me to extract its value and edit it successfully. (defun c:cambiar_nombre ( / ent selobj progre) ;; Define el valor que se asignará al nombre del punto (setq progre "0+020") ;; Cambia este valor si lo necesitas dinámicamente ;; Solicita al usuario seleccionar un punto COGO en el dibujo (setq ent (entsel "\nSeleccione un punto COGO: ")) (if (and ent (setq selobj (vlax-ename->vla-object (car ent)))) (progn ;; Verifica si el objeto tiene la propiedad "Name" (if (vlax-property-available-p selobj 'Name) (progn ;; Muestra el valor actual de "Name" (princ (strcat "\nNombre actual: " (vlax-get selobj 'Name))) ;; Modifica el valor de "Name" con el contenido de "progre" (vlax-put selobj 'Name progre) (princ (strcat "\nNuevo nombre asignado: " progre)) ) (princ "\nEl objeto seleccionado no tiene la propiedad 'Name'.") ) ) (princ "\nNo se seleccionó un punto válido.") ) (princ) ) Edited Sunday at 10:53 PM by cjc_cristian Quote
cjc_cristian Posted Sunday at 10:59 PM Author Posted Sunday at 10:59 PM (edited) Now, I would appreciate it if you could help me to extract, using Lisp, the X, Y coordinates of a cog point selected by the user, it would be very helpful since I still do not know many useful functions. Edited Monday at 01:20 AM by cjc_cristian Quote
BIGAL Posted Monday at 03:53 AM Posted Monday at 03:53 AM The cogo point has a variable called location. (setq obj (vlax-ename->vla-object (car (entsel "\nPick cogo point ")))) ; vl 3d point convert to plain lisp (setq pt1 (vlax-safearray->list (vlax-variant-value (vlax-get-property obj "Location")))) (setq ht (nth 2 pt1)) ; Z val (setq X (nth 0 pt1)) (setq y (nth 1 pt1)) Quote
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.