Jump to content

Recommended Posts

Posted (edited)

Hi,
I have a lisp file for C3d, (found in a forum a while back,) which I use to add vertices to polylines with one click. It saves a lot of time. My colleague wants to use it in ProgeCad, but we can't get it to work.
It loads fine in ProgeCad,  but when he types the command, nothing happens.
When I type it in C3d, it asks me to click on the polyline where I want the new vertex, and it puts a vertex where I click. In Progecad, it doesn't even ask. Type the commmand, hit enter, and it just  ignores the input.
I've read that some lisps need editing to work in PG but I have no idea what should be altered. I'm no coder.
Can anyone help me, please?

Here's the lisp:

;;  Revised Version by CAB at TheSwamp.org for bulge & width

;;  Revised by gile for coordinate systems transformations  09/16/2007

;;  no error checking, i.e. locked layers

;;  Only works with LWpolylines

;;

;;  NOTE: this is a work in progress :)

;;



(defun c:addvertex (/ ent ew norm nw obj old_bulge pt-o pt-w sw vi vr)


;; K*BULGE by gile

;; Returns a bulge which is proportional to reference bulge

;; Arguments :

;; b: the reference bulge

;; k: lthe ratio (between arc lengthes or angles)

;; Exemple:

;; (k*bulge 1.0 0.5) -> 0.414214

(defun k*bulge (b k / a)

  (setq a (atan b))

  (/ (sin (* k a)) (cos (* k a)))

)


  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

  (vla-StartUndoMark doc)


  (setq ent (entsel "\n Select point on polyline to add vertex: "))

  (if (and ent

           (equal (assoc 0 (entget (car ent))) '(0 . "LWPOLYLINE"))

      )

    (progn

      (setq norm (cdr (assoc 210 (entget (car ent)))) ; get the pline normal

          pt-w (vlax-curve-getclosestpointto (car ent) (trans (cadr ent) 1 0)) ; new point (WCS)

          pt-o (trans pt-w 0 norm) ; new point (OCS)

            pt-o (list (car pt-o) (cadr pt-o)) ; 2D point

            vr (vlax-curve-getparamatpoint (car ent) pt-w)

            vi (fix vr)  ; vertex index, one before picked point

            vr (- vr vi) ; vertex remainder, at picked point

      )


      (setq obj       (vlax-ename->vla-object (car ent))

            old_bulge (vla-getbulge obj vi)

      )

      (vla-GetWidth obj vi 'sw 'ew) ; startWidth endWidth

      (vlax-invoke obj 'AddVertex (1+ vi) pt-o) ; add new vertex

      (if (equal sw ew 0.0001) ; update pline width

        (vla-SetWidth obj (1+ vi) sw ew)

        (progn ; width is a taper

          (setq nw (* (+ sw ew) vr))

          (vla-SetWidth obj vi sw nw)

          (vla-SetWidth obj (1+ vi) nw ew)

        )

      )

      (if (not (zerop old_bulge)) ; got a bulge

        (progn ; update new segments with matching radius

          (vla-setbulge obj vi (k*bulge old_bulge vr))

          (vla-setbulge obj (1+ vi) (k*bulge old_bulge (- 1 vr)))

        )

      )

    )


  )

  (vla-EndUndoMark doc)


  (princ)

)

(prompt "\nAdd Vertex to LW plines loaded, AddVertex to run.")

(princ)

 

Edited by SLW210
Added Code Tags!
Posted (edited)

Welcome to the forum!

 

The commands that start with "vla" overlap with VisualLISP. I am still piecing together the relationship between VisualLISP and AutoLISP. You need the MS Visual Studio to write VisualLISP code, which is why I've resisted using it. There are VisualLISP commands accessible from AutoLISP (hence the word "overlap").

 

I don't know how well ProgeCAD supports VisualLISP. Apparently they are still working on it, because many functions aren't supported. When the ProgeCAD interpreter tries to run "vla-get-ActiveDocument", for instance, it's not going to find that command. Everything that depends on accessing the current drawing, then, is blocked, including the Undo list.

 

See this page for a list of VisualLISP commands progeCAD recognizes. VLA-GET-ACTIVEDOCUMENT isn't on it, while VLAX-CURVE-GETCLOSESTPOINTTO is.

 

Okay, forget everything I just said. I think you can run this program if you remove these statements at the top:


 

  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

  (vla-StartUndoMark doc)

 

and this one at the bottom:


 

  (vla-EndUndoMark doc)

 

If that doesn't work, tell us what happened, and we'll go from there. And don't forget to save a copy of the original code.

Edited by CyberAngel
Posted
20 hours ago, CyberAngel said:

Welcome to the forum!

 

The commands that start with "vla" overlap with VisualLISP. I am still piecing together the relationship between VisualLISP and AutoLISP. You need the MS Visual Studio to write VisualLISP code, which is why I've resisted using it. There are VisualLISP commands accessible from AutoLISP (hence the word "overlap").

 

I don't know how well ProgeCAD supports VisualLISP. Apparently they are still working on it, because many functions aren't supported. When the ProgeCAD interpreter tries to run "vla-get-ActiveDocument", for instance, it's not going to find that command. Everything that depends on accessing the current drawing, then, is blocked, including the Undo list.

 

See this page for a list of VisualLISP commands progeCAD recognizes. VLA-GET-ACTIVEDOCUMENT isn't on it, while VLAX-CURVE-GETCLOSESTPOINTTO is.

 

Okay, forget everything I just said. I think you can run this program if you remove these statements at the top:


 

  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

  (vla-StartUndoMark doc)

 

and this one at the bottom:


 

  (vla-EndUndoMark doc)

 

If that doesn't work, tell us what happened, and we'll go from there. And don't forget to save a copy of the original code.

Thank you. 
It got us a step closer. When Mark types  the command ADDVERTEX, he now gets the prompt to click on the line where he wants a vertex, but when he clicks he gets the error message 'bad argument command' three times in a row.

Posted

You'll likely have to remove all of the vla and vlax commands and replace them with custom AutoLisp functions that handle the polyline geometry and entity modification. (I don't have ProgeCAD to check).

Posted

Is there any sort of conversion tutorial or list somewhere? Something that can translate Visual Lisp into Auto Lisp?

Posted
On 6/19/2024 at 5:11 AM, Archaeologist said:

Thank you. 
It got us a step closer. When Mark types  the command ADDVERTEX, he now gets the prompt to click on the line where he wants a vertex, but when he clicks he gets the error message 'bad argument command' three times in a row.

You probably need this command at the beginning:

(vl-load-com)

which loads the library for all the Visual LISP commands--as you might expect from the name.

Posted

Autocad has VLIDE Bricscad has Blade these are run time programs for developing lisp code included is "Debug" you can look at where code failed this would give us big clues about what is happening. I dont know if Progecad has similar.

 

About all we can do without Progecad is to make you some test lines of code and see if they fail you would copy say the 1 line to the command line and hopefully it runs.

(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

Should return #<VLA-OBJECT IAcadDocument 0000000063A064F8> etc

 

(vlax-curve-getclosestpointto (car (entsel "\pick a line or pline")) (getpoint "\nPick near the object but not on it "))

Should return (55.2192513267315 108.828700429917 0.0) (X Y Z)  of a point on the line/pline.

 

  • 5 months later...
Posted

Suggest you use ChatGPT, start small, get output, back feed the issues or problems and keep working.   I have not written one line of LISP code before, but I wanted to take data from a text file, match the station number on the drawing to a station  number on the text file, then place text data from the text file below the station number( of several cross section).    It was a bit frustrating over a two day period, having to tell ChatGPT to drop back and rework code, numerous times  but I was able to achieve this.

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...