+ Reply to Thread
Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 11 to 20 of 30
  1. #11
    Full Member
    Using
    AutoCAD 2016
    Join Date
    Aug 2016
    Posts
    31

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by Lee Mac View Post
    Here is an example:
    Code:
    (defun c:px ( / cmd ent enx ped )
        (setvar 'errno 0)
        (while (/= 52 (getvar 'errno))
            (setvar 'errno 0)
            (setq ent (car (entsel "\nSelect polyline <exit>: ")))
            (cond
                (   (= 7 (getvar 'errno))
                    (prompt "\nMissed, try again.")
                )
                (   (null ent)
                    (prompt "\nExit.")
                )
                (   (/= "LWPOLYLINE" (cdr (assoc 0 (setq enx (entget ent)))))
                    (prompt "\nSelected object is not an LWPolyline.")
                )
                (   (= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (cdr (assoc 8 enx)))))))
                    (prompt "\nSelected polyline is on a locked layer.")
                )
                (   (setq cmd (getvar 'cmdecho)
                          ped (getvar 'peditaccept)
                    )
                    (setvar 'cmdecho 0)
                    (setvar 'peditaccept 1)
                    (command
                        "_.explode" ent
                        "_.pedit" "_m" "_p" "" "_w" (cdr (assoc 43 enx)) ""
                    )
                    (setvar 'peditaccept ped)
                    (setvar 'cmdecho cmd)
                )
            )
        )
        (princ)
    )
    WOW!!! Now that is the right way to do it!!!
    on a side note, i keep re-writing and re-writing my code cuz i kept getting an error. turns out the global was not set and i kept getting an error.

    after i ran yours and it also didn't work, i knew something was wrong. never did i think to check if the global width was set.

    maybe there could be a variable to select either starting width or ending width if global is not set.

  2. #12
    Full Member
    Using
    AutoCAD 2016
    Join Date
    Aug 2016
    Posts
    31

    Default

    Quote Originally Posted by Lee Mac View Post
    (command
    "_.explode" ent
    "_.pedit" "_m" "_p" "" "_w" (cdr (assoc 43 enx)) ""
    )
    I learn more from your code then from the book I'm reading.
    I see now that I don't need to setq pw for assoc 43, i can simply invoke assoc 43 when i need that number.

    I'm still a caveman in coding, but i'm trying to make that fire burn. that should be my CADTutor motto. lol.

  3. #13
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    Quote Originally Posted by Grrr View Post
    Code:
    (/= (cdr (assoc 70 (entget (tblobjname "LAYER" (cdr (assoc 8 enx)))))) 4)
    I might need to study deeper this logand function as its not the first time I see its in use.
    Indeed - DXF group 70 is typically bit-coded and therefore may not be equal to 4 if locked with other properties set (for example, test your code with an object residing on a locked layer which is frozen in new viewports).

    Quote Originally Posted by RubberDinero View Post
    I learn more from your code then from the book I'm reading.
    That's great to hear!
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  4. #14
    Full Member
    Using
    AutoCAD 2016
    Join Date
    Aug 2016
    Posts
    31

    Default

    Quote Originally Posted by Lee Mac View Post
    (command
    "_.explode" ent
    "_.pedit" "_m" "_p" "" "_w" (cdr (assoc 43 enx)) ""
    )
    Where the following code is
    Code:
    (cdr (assoc 43 enx))
    would it be possible to make that a variable and add an (if parameter stating that if the Constant width is null and (cdr (assoc 40)) is equal to (cdr (assoc 41) then width would be set to starting width.
    If different, ask user input to choose either start or end
    i.e. (initget "Start End"
    where start is (cdr (assoc 40)) and end is (cdr (assoc 41))

    i think that would wrap up this lisp of all errors.

  5. #15
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,060

    Default

    Quote Originally Posted by Lee Mac View Post
    Indeed - DXF group 70 is typically bit-coded and therefore may not be equal to 4 if locked with other properties set (for example, test your code with an object residing on a locked layer which is frozen in new viewports).
    That was exactly my thought, I wasn't sure how to structure your answer as a question in my previous post, but you answered already. (english is not my first langugage).
    Thank you for elaborating!

  6. #16
    Super Member
    Using
    Civil 3D 2015
    Join Date
    Aug 2015
    Posts
    508

    Default

    Quote Originally Posted by RubberDinero View Post
    Where the following code is
    Code:
    (cdr (assoc 43 enx))
    would it be possible to make that a variable and add an (if parameter stating that if the Constant width is null and (cdr (assoc 40)) is equal to (cdr (assoc 41) then width would be set to starting width.
    If different, ask user input to choose either start or end
    i.e. (initget "Start End"
    where start is (cdr (assoc 40)) and end is (cdr (assoc 41))

    i think that would wrap up this lisp of all errors.
    Hint, look at dxf group codes 40 and 41 to find the starting and ending widths. Just need to put in a conditional statement where if dxf group code 43 is null, then move onto the 40 or 41 depending on your preference.

  7. #17
    Full Member
    Using
    AutoCAD 2016
    Join Date
    Aug 2016
    Posts
    31

    Default

    Code:
    (defun c:px2 ( / cmd ent enx ped pw1 )
        (setvar 'errno 0)
        (while (/= 52 (getvar 'errno))
            (setvar 'errno 0)
            (setq ent (car (entsel "\nSelect polyline <exit>: ")))
            (cond
                (   (= 7 (getvar 'errno))
                    (prompt "\nMissed, try again.")
                )
                (   (null ent)
                    (prompt "\nExit.")
                )
                (   (/= "LWPOLYLINE" (cdr (assoc 0 (setq enx (entget ent)))))
                    (prompt "\nSelected object is not an LWPolyline.")
                )
                (   (= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (cdr (assoc 8 enx)))))))
                    (prompt "\nSelected polyline is on a locked layer.")
                )
                (   (setq cmd (getvar 'cmdecho)
                          ped (getvar 'peditaccept)
                    )
                    (setvar 'cmdecho 0)
                    (setvar 'peditaccept 1)
    		(if (= (cdr (assoc 43 enx)) nil)
    			(if (= (cdr (assoc 41 enx)) (cdr (assoc 40 enx)))
    				(setq pw1 (cdr (assoc 40 enx)))
    				(initget "Start End (cdr (assoc 40 enx)) (cdr (assoc 41 enx)))
    				(setq pw1 (getkword "\nEnter an Option (Start/End): "))
    			)
    			(setq pw1 (cdr (assoc 43 enx)))
    		)
                    (command
                        "_.explode" ent
                        "_.pedit" "_m" "_p" "" "_w" pw1 ""
                    )
                    (setvar 'peditaccept ped)
                    (setvar 'cmdecho cmd)
                )
            )
        )
        (princ)
    )
    I tried my caveman coding, but is it not possible to have an "IF" statement within an "IF" statement? or did I write the "(=" statement wrong?

  8. #18
    Full Member
    Using
    AutoCAD 2016
    Join Date
    Aug 2016
    Posts
    31

    Default

    Code:
    (defun c:px2 ( / cmd ent enx ped pw1 )
        (setvar 'errno 0)
        (while (/= 52 (getvar 'errno))
            (setvar 'errno 0)
            (setq ent (car (entsel "\nSelect polyline <exit>: ")))
            (cond
                (   (= 7 (getvar 'errno))
                    (prompt "\nMissed, try again.")
                )
                (   (null ent)
                    (prompt "\nExit.")
                )
                (   (/= "LWPOLYLINE" (cdr (assoc 0 (setq enx (entget ent)))))
                    (prompt "\nSelected object is not an LWPolyline.")
                )
                (   (= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (cdr (assoc 8 enx)))))))
                    (prompt "\nSelected polyline is on a locked layer.")
                )
                (   (setq cmd (getvar 'cmdecho)
                          ped (getvar 'peditaccept)
                    )
                    (setvar 'cmdecho 0)
                    (setvar 'peditaccept 1)
    		(if (= (cdr (assoc 43 enx)) nil)
    			(if (= (cdr (assoc 41 enx)) (cdr (assoc 40 enx)))
    				(setq pw1 (cdr (assoc 40 enx)))
    				((initget "Start End (cdr (assoc 40 enx)) (cdr (assoc 41 enx))") (setq pw1 (getkword "\nEnter an Option (Start/End): ")))
    			)
    			(setq pw1 (cdr (assoc 43 enx)))
    		)
                    (command
                        "_.explode" ent
                        "_.pedit" "_m" "_p" "" "_w" pw1 ""
                    )
                    (setvar 'peditaccept ped)
                    (setvar 'cmdecho cmd)
                )
            )
        )
        (princ)
    )
    HAD FORGOT TO PUT A END QUOTE!!! LOL!
    But now when i do getkword it doesn't accept Start or End, it says invalid.

  9. #19
    Full Member
    Using
    AutoCAD 2016
    Join Date
    Aug 2016
    Posts
    31

    Default

    Quote Originally Posted by RubberDinero View Post
    But now when i do getkword it doesn't accept Start or End, it says invalid.
    i know see that initget are the acceptable keywords. now i need to set up the if statements.

  10. #20
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,060

    Default

    Registered forum members do not see this ad.

    RubberDinero, check this:
    http://www.lee-mac.com/promptwithdefault.html
    then check this (especially the last example code - for your case):
    http://www.afralisp.net/autolisp/tut...nditionals.php

Similar Threads

  1. [LISP] Scaling just the "x" and "y" axis
    By chiimayred in forum AutoLISP, Visual LISP & DCL
    Replies: 31
    Last Post: 16th May 2016, 02:46 pm
  2. HELP to include "AcDbAlignedDimension" code for a "Dimension deleting" LISP
    By vernonlee in forum AutoLISP, Visual LISP & DCL
    Replies: 14
    Last Post: 10th Apr 2015, 04:03 pm
  3. Automatically updating "defined width" attributes for MTEXT?
    By Comatosis in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 1
    Last Post: 8th Dec 2011, 09:59 pm
  4. Polyline global width keeps showing up as 1"
    By ammobake in forum AutoCAD General
    Replies: 5
    Last Post: 4th Jun 2009, 10:52 pm
  5. Finding the "width" of a block (.NET)
    By askrius in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 8th Sep 2008, 10:21 pm

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts