Author Topic: Lisp Alteration  (Read 2884 times)

0 Members and 1 Guest are viewing this topic.

mmccormack

  • Mosquito
  • Posts: 9
Lisp Alteration
« on: April 11, 2023, 05:08:37 AM »
Hi,

Can anyone help me with an alteration to a lisp file...

I use the 'Flex 17 CAB.lsp' its great lisp and helps me out alot...  I was wondering if i could get an alteration done to it whereby it fills the flex in with a solid hatch and a transparency of 50 and colour set to bylayer...  and also for the outline to be colour white...

Many Thanks in Advance...

Matt
« Last Edit: April 13, 2023, 06:59:24 AM by mmccormack »

BIGAL

  • Swamp Rat
  • Posts: 1445
  • 40 + years of using Autocad
Re: Lisp Alteration
« Reply #1 on: April 11, 2023, 08:29:40 PM »
Answers were provided at forums/autodesk.
A man who never made a mistake never made anything

mmccormack

  • Mosquito
  • Posts: 9
Re: Lisp Alteration
« Reply #2 on: April 13, 2023, 02:59:53 AM »
do you have a link to that post/forum?   I originally asked the question first in the Autodesk forums and they replied why dont you ask the owners of the lisp routine, so I've come here to ask the owners the same question... and now your reply is sending back to the Autodesk forums, I feel like I'm going round in circles, catch my drift!  :-)

JohnK

  • Administrator
  • Seagull
  • Posts: 10669
Re: Lisp Alteration
« Reply #3 on: April 13, 2023, 09:04:56 AM »
I believe you are not getting the help you need because of your lack of wanting to learn. TheSwamp has always been a place where programmers hang out to teach and share (the site costs a lot of money to run and it does not exist just so people can request programs).  Note: the better programmers tend to be a bit busy (hence why they are `better programmers`) so if you alter your question(s), try a little yourself, and be patient, and ask questions you wish to learn about, you may get a bite.

You essentially want only one alteration to the file, and I don't think CAB intended for that program to never be altered and shared (he probably just slapped that license on and never paid much attention to it) but Mr. Cooper (on the adesk forums) is correct in not changing the file.

CAB is a very nice guy, worked on that routine for a long time, and his wishes should be honored (if you want changes, learn how and you should try to do the changes yourself). We can show you how (to change the file/program/get started/etc), you just need to do a little research and ask questions.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

BIGAL

  • Swamp Rat
  • Posts: 1445
  • 40 + years of using Autocad
Re: Lisp Alteration
« Reply #4 on: April 14, 2023, 04:17:48 AM »
Kent Cooper gave an answer to the problem over at Forums/autodesk hatching the double plines created.

He also noted the copyright agreement in the code that meant anyone other than a poster changing the code for their personal use was breaching the copyright.

I am sure CAB would give permission to add the hatch function to someone to post on the open forums as say a new version. Suitably noted original by CAB modified by ?????

FOUND IT
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/alteration-to-a-lisp-file/td-p/11877634
« Last Edit: April 14, 2023, 04:41:52 AM by BIGAL »
A man who never made a mistake never made anything

mmccormack

  • Mosquito
  • Posts: 9
Re: Lisp Alteration
« Reply #5 on: April 20, 2023, 11:10:57 AM »
Thank you Bigal for your message, its most appreciated

I've sent a message to CAB, hopefully he'll respond as and when he can, can appreciate we're all busy people, so yeah happy either way with whatever he says. :-)


   

ronjonp

  • Needs a day job
  • Posts: 7533
Re: Lisp Alteration
« Reply #6 on: April 20, 2023, 04:34:28 PM »
Thank you Bigal for your message, its most appreciated

I've sent a message to CAB, hopefully he'll respond as and when he can, can appreciate we're all busy people, so yeah happy either way with whatever he says. :-)
When you look at how the duct is drawn, your modification is a big ask.

One way to easily generate the closed outline is to draw a rectangle around the duct then use the BOUNDARY command and pick a point outside the duct. Then you have something to hatch :).

Lee also has an outline program that would work too. You need to take the delete objects out and generate a hatch from the boundary!
http://www.lee-mac.com/outlineobjects.html
« Last Edit: April 20, 2023, 04:46:05 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

JohnK

  • Administrator
  • Seagull
  • Posts: 10669
Re: Lisp Alteration
« Reply #7 on: April 20, 2023, 04:48:48 PM »
ronjonp, if you have it up can you double check if it will hatch as it was by selecting objects. I checked quick and I think it worked but it could have been a fluke (and/or I was just thinking of checking to see if it worked as it was and my overworked brain just convinced myself that I actually checked).
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

ronjonp

  • Needs a day job
  • Posts: 7533
Re: Lisp Alteration
« Reply #8 on: April 20, 2023, 06:20:41 PM »
ronjonp, if you have it up can you double check if it will hatch as it was by selecting objects. I checked quick and I think it worked but it could have been a fluke (and/or I was just thinking of checking to see if it worked as it was and my overworked brain just convinced myself that I actually checked).
I just tested in AutoCAD 2024 and
Quote
Command:  HATCH
Select objects or [picK internal point/Undo/seTtings]:1 found
Select objects or [picK internal point/Undo/seTtings]:
Unable to fill the boundary with solid.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

BIGAL

  • Swamp Rat
  • Posts: 1445
  • 40 + years of using Autocad
Re: Lisp Alteration
« Reply #9 on: April 20, 2023, 08:48:40 PM »
Pretty sure if you re read the post by kent he explains how to get it to work, by add lines to the ends adding to the correct pline need to do the 2 ends

This took like 20 seconds had to think about it. Would be faster once know how.
A man who never made a mistake never made anything

liuhe

  • Mosquito
  • Posts: 8
Re: Lisp Alteration
« Reply #10 on: April 20, 2023, 11:22:35 PM »
Code: [Select]
;;;=======================[ FlexDuct.lsp ]==============================
;;; Author: Copyright?2007 Charles Alan Butler
;;; Contact or Updates  @  www.TheSwamp.org
;;; Version:  1.7   Feb. 21,2008
;;; Purpose: Create Flex Duct from a centerline that the user picks
;;;    Centerline may be anything vla-curve will handle
;;; Sub_Routines:     
;;;    makePline which creates a LW Polyline
;;; Restrictions: UCS is supported
;;;    Duct Layer is hard coded, see var Flexlayer
;;;    No error handler at this time
;;; Known Issues:
;;;    Tight curves cause pline jacket distortion
;;;    Added warning when this is about to occur
;;; Returns:  none
;;;=====================================================================
;;;   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED     ;
;;;   WARRANTY.  ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR  ;
;;;   PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED.            ;
;;;                                                                    ;
;;;  You are hereby granted permission to use, copy and modify this    ;
;;;  software without charge, provided you do so exclusively for       ;
;;;  your own use or for use by others in your organization in the     ;
;;;  performance of their normal duties, and provided further that     ;
;;;  the above copyright notice appears in all copies and both that    ;
;;;  copyright notice and the limited warranty and restricted rights   ;
;;;  notice below appear in all supporting documentation.              ;
;;;=====================================================================

(defun c:Flex (/ cl-ent    ribWidth  RibShort  RibLong patternName collar
dist    steps     ribFlag   pt curAng
curDer    RibPtLst1 RibPtLst2 p1 p2
doc    space     cflag     cl-len ribRadius
tmp    NewPline  NewPline2 NewPline3 I
J    LST1      LST2      LST3
pl1    pl2      cnt       errflag InsulThick
FlexColor FlexLayer ss
)
  (vl-load-com)
  (setq Doc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-endundomark doc)
  (vla-startundomark doc)

  ;; \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
 
  ;;  Change these if you want
 
  (setq FlexLayer "0")   ; put your Duct layer here
  (setq FlexColor acred) ; put your color over ride here or Bylayer
  (setq InsulThick 0)    ; to be added to duct diameter, use 2 for 1" insulation
  (setq collar 6.0)      ; collar length at each end
  (setq DelCL nil)       ; delete the centerline t=Yes nil=No
  (setq GroupFlex t)     ; make flex duct a Group t=Yes nil=No
 
  (vla-SetRGB col1 114 116 48 );fill color
  (setq patternName "SOLID");hatch pattern
 
  ;; \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/


  ;;   --------   Local Functions   ---------

  ;;  Expects pts to be a list of 2D or 3D points
  (defun makePline (spc pts)
    (if (= (length (car pts)) 2) ; 2d point list
      (setq pts (apply 'append pts))
      (setq
        pts (apply 'append (mapcar '(lambda (x) (list (car x) (cadr x))) pts))
      )
    )
    (setq
      pts (vlax-make-variant
            (vlax-safearray-fill
              (vlax-make-safearray vlax-vbdouble (cons 0 (1- (length pts))))
              pts
            )
          )
    )
    (vla-addlightweightpolyline spc pts)
  )
  ;;   -------------------------------------


  ;;  Get the Duct Diameter, global variable
  (or duct:dia (setq duct:dia 16.0)) ; default value

  (while            ; Main Loop
    (progn
      (prompt (strcat "\nDuct diameter is set to "
                      (vl-princ-to-string duct:dia)
              )
      )
      (setvar "errno" 0) ; must pre set the errno to 0
      (initget "Diameter")
      (setq cl-ent
             (entsel (strcat "\nSelect center line of flex duct.[Diameter]<"
                             (vl-princ-to-string duct:dia)
                             "> Enter to quit."))
      )

      (cond
        ((= (getvar "errno") 52) ; exit if user pressed ENTER
         nil        ; exit loop
        )
        ((= cl-ent "Diameter")
         (initget (+ 2 4))
         (setq
           tmp (getdist
                 (strcat "\nSpecify duct diameter <" (rtos duct:dia) ">: ")
               )
         )
         (and tmp (setq duct:dia tmp))
         t          ; stay in loop
        )

        ((not (null cl-ent))
         ;;  check entity before making the duct
         (if (not (vl-catch-all-error-p
                    (setq tmp (vl-catch-all-apply
                                'vlax-curve-getpointatparam
                                (list (car cl-ent) 0.0)
                              )
                    )
                  )
             )
           (progn   ; OK to make duct
             (setq cl-ent   (car cl-ent) ; Center Line
                   ribWidth (* duct:dia 0.167)
                   RibShort (+ duct:dia InsulThick) ; add insulation
                   RibLong  (+ RibShort (* ribWidth 2))
             )

             ;;  centerline length
             (setq cl-len (vlax-curve-getdistatparam
                            cl-ent
                            (vlax-curve-getendparam cl-ent)
                          )
                   cl-len (- cl-len (* collar 2.0))
                   steps  (/ cl-len ribWidth)
             )
             (if (= (logand (fix steps) 1) 1) ; T = odd
               (setq steps (fix steps))
               (setq steps (1+ (fix steps)))
             )
             (setq ribWidth (/ (- cl-len 0.25) (1- steps))
                   dist     collar ;0.125 ; distance along center line
             )

           
             (setq ribFlag 0
                   cflag   t
                   cnt     0
                   pl1     nil
                   pl3     nil
                   errflag nil
             )

             ;;  ----------   Create Rib End Points   -----------
             (repeat steps
               (setq pt (vlax-curve-getpointatdist cl-ent dist))
               (setq
                 curDer (trans
                          (vlax-curve-getfirstderiv
                            cl-ent
                            (vlax-curve-getparamatpoint cl-ent pt)
                          )
                          0
                          1
                        )
               )
               ;; Get angle 90 deg to curve
               (setq curAng (+ (/ pi 2) (angle '(0 0) curDer)))
               (setq ribRadius (if (zerop ribFlag)
                                 (/ RibShort 2)
                                 (/ RibLong 2)
                               )
               )
               (setq pt (trans pt 0 1)) ; WCS > UCS
               (setq p1 (polar pt curAng ribRadius))
               (setq p2 (polar pt (+ pi curAng) ribRadius))
               (if cflag ; create start collar points
                 (setq RibPtLst1 (list (polar p1 (angle curDer '(0 0)) collar))
                       RibPtLst2 (list (polar p2 (angle curDer '(0 0)) collar))
                       cflag     nil
                 )
               )

               ;;  this collection method creates a woven pline
               (cond
                 ((null pl1) ; first time through
                  (setq RibPtLst1 (cons p1 RibPtLst1)
                        RibPtLst2 (cons p2 RibPtLst2)
                  )
                 )
                 ((= (logand (setq cnt (1+ cnt)) 1) 1) ; T = odd cnt
                  (setq RibPtLst1 (cons pl2 RibPtLst1)
                        RibPtLst1 (cons p2 RibPtLst1)
                        RibPtLst2 (cons pl1 RibPtLst2)
                        RibPtLst2 (cons p1 RibPtLst2)
                  )
                 )
                 ((setq RibPtLst1 (cons pl1 RibPtLst1)
                        RibPtLst1 (cons p1 RibPtLst1)
                        RibPtLst2 (cons pl2 RibPtLst2)
                        RibPtLst2 (cons p2 RibPtLst2)
                  )
                 )
               )
               (if (and pl3 (inters p1 p2 pl3 pl4 t))
                 (setq errflag t)
               )
               (setq ribFlag (- 1 ribFlag) ; toggle flag
                     dist    (+ ribWidth dist)
                     pl3     pl1
                     pl4     pl2
                     pl1     p1
                     pl2     p2
               )
             )
             ;;  create end collar points
             (setq RibPtLst1 (cons p2 RibPtLst1)
                   RibPtLst1 (cons (polar p2 (angle '(0 0) curDer) collar) RibPtLst1)
                   RibPtLst2 (cons p1 RibPtLst2)
                   RibPtLst2 (cons (polar p1 (angle '(0 0) curDer) collar) RibPtLst2)
             )

             ;;  --------   point list to WCS   ------------
             (setq RibPtLst1 (mapcar '(lambda (x) (trans x 1 0)) RibPtLst1))
             (setq RibPtLst2 (mapcar '(lambda (x) (trans x 1 0)) RibPtLst2))

             ;;  --------   create jacket plines   ------------
             (or space
                 (setq space
                        (if (zerop (vla-get-activespace doc))
                          (if (= (vla-get-mspace doc) :vlax-true)
                            (vla-get-modelspace doc) ; active VP
                            (vla-get-paperspace doc)
                          )
                          (vla-get-modelspace doc)
                        )
                 )
             )

             (cond
               ((and errflag
                     (progn
                       (initget "Yes No")
                       (= "No"
                          (cond
                            ((getkword "\nTurns too tight, Proceed? [Yes/No]<Yes>:"))
                            ("Yes")))
                       )
                     )
                t ; skip the create & stay in loop
               )
               (
       (setq newpline (makePline space RibPtLst1))
                (vla-put-layer newpline Flexlayer)
                (if FlexColor
                  (vla-put-color newpline FlexColor)
                )
                ;;(vla-put-elevation newpline z)

                (setq newpline2 (makePline space RibPtLst2))
                (vla-put-layer newpline2 Flexlayer)
                (if FlexColor
                  (vla-put-color newpline2 FlexColor)
                )
                ;;(vla-put-elevation newpline z)
               
                (if DelCL (entdel cl-ent)) ; remove the centerline object
                (if GroupFlex
  (progn
    (setq ss (ssadd))
    (ssadd (vlax-vla-object->ename newpline) ss)
    (ssadd (vlax-vla-object->ename newpline2) ss)
    (or DelCl (ssadd cl-ent ss))
    (if (vl-cmdf "_.-group" "_create" "*" "" ss "")
      (princ "\nGrouping Done")
      (princ "\nError Grouping")
    )
  )
)

          ;;; The following are newly added for filling
(SETQ I    1
      J    (+ I 2)
      LST1 NIL
)
(WHILE (AND (NTH I RibPtLst1) (NTH J RibPtLst2))
  (SETQ LST1 (CONS (NTH J RibPtLst2)
   (CONS (NTH I RibPtLst1) LST1)
     )
i (+ 4 I)
J (+ I 2)
  )
)
(SETQ LST1 (CONS (CAR RibPtLst1) (REVERSE LST1))
      I    1
      J    (+ I 2)
      LST2 NIL
)
(WHILE (AND (NTH I RibPtLst2) (NTH J RibPtLst1))
  (SETQ LST2 (CONS (NTH J RibPtLst1)
   (CONS (NTH I RibPtLst2) LST2)
     )
i (+ 4 I)
J (+ I 2)
  )
)
(SETQ LST2 (CONS (CAR RibPtLst2) (REVERSE LST2))
      LST3 (CONS (CAR LST2) (APPEND LST1 (REVERSE LST2)))
      newpline3 (vlax-vla-object->ename
  (makePline space LST3)
)
)
(vl-cmdf "-hatch" "P" patternName "S" newpline3 "" "")
        (ENTDEL newpline3)
(vla-put-TrueColor (vlax-ename->vla-object(entlast))col1)
(vl-cmdf  "DRAWORDER" (entlast) "" "B")
 
               )
             ) ; cond
           )        ; progn
           (princ "\nError - Can not use that object, Try again.")
         )          ; endif
         t
        )
        (t (princ "\nMissed Try again."))
      )             ; cond stmt
    )               ; progn
  )                 ; while
  (vla-endundomark doc)
  (vlax-release-object space)
  (vlax-release-object doc)
  ;;-----------  E N D   O F   L I S P  ----------------------------
  (princ)
)
(prompt "\nFlex Duct loaded, Enter FLEX to run.")
(princ)

I have made some code additions to make the entire code so perfect, but it has been able to achieve the desired results and run
« Last Edit: April 21, 2023, 01:47:51 AM by liuhe »

mmccormack

  • Mosquito
  • Posts: 9
Re: Lisp Alteration
« Reply #11 on: April 21, 2023, 11:00:44 AM »
Many thanks all, for taking the time to reply and helping out with my question... its really appreciated and I'm most grateful for it...

liuhe
I've copied that new lisp routine (loaded successfully) and tried it out but I'm getting an error in my CAD, do you know what is causing this? see below screenshot


JohnK

  • Administrator
  • Seagull
  • Posts: 10669
Re: Lisp Alteration
« Reply #12 on: April 21, 2023, 11:52:39 AM »
liuhe, Nicely done.

mmccormak,
You don't need to post a screenshot; a copy-paste of your command line would have been sufficient. The problem you are having is because liuhe didn't supply a few functions related to setting the color of the hatch. If you comment out two lines the code should work.

SIDE NOTE: CAB was up to version 2.3. The versions you guys are using is version 1.7.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

mmccormack

  • Mosquito
  • Posts: 9
Re: Lisp Alteration
« Reply #13 on: April 24, 2023, 03:36:56 AM »
Thank you John.. appreciate your response, but a little confused, I dont understand when you said  "if you comment out two lines" what does comment out mean? and which two lines?  beg my pardon for my ignorance, just trying to understand....

:-)


liuhe

  • Mosquito
  • Posts: 8
Re: Lisp Alteration
« Reply #14 on: April 24, 2023, 04:46:34 AM »
Because I am using CAD 2024, I am not sure if other versions of CAD are working properly. You can try commenting out this line of code
(vla-put-TrueColor (vlax-ename->vla-object(entlast))col1)
col1 It is an environment variable and the color of solid
Or use other methods to make color changes