+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Senior Member tmelancon's Avatar
    Computer Details
    tmelancon's Computer Details
    Operating System:
    Windows 7 Professional
    Computer:
    Dell Optiplex 7010
    CPU:
    i3-3220 Processor (Quad Core, 3.30GHz)
    RAM:
    8GB
    Graphics:
    HD2500 Graphics
    Primary Storage:
    500GB
    Secondary Storage:
    2TB External Backup
    Monitor:
    Dual Dell 27" Monitors!!
    Discipline
    Multi-disciplinary
    tmelancon's Discipline Details
    Occupation
    CAD Operations/Design
    Discipline
    Multi-disciplinary
    Details
    CAD Design, CAD Management, Project Management, ISO Drawings, Pressure Vessels, Inspection Reports, Data Analysis, Work Scope Recommendations, Troubleshooting, and anything else the boss needs to maximize efficiency. Also proficient in Electrical Engineering/Lighting Design and LEED Green Energy
    Using
    AutoCAD 2015
    Join Date
    Jun 2013
    Posts
    327

    Question Offset LISP using VLA-OFFSET & VLA-PUT-LAYER... Need Help

    Registered forum members do not see this ad.

    Hello, I currently use a routine that offsets a line in both directions based on a specified distance in the routine. After we run the command we usually have to select the two offset lines and put them on a specific layer, in this case "Structure".

    I am trying to just add to the routine so the offset lines are automatically put on that layer for us but for some reason when we run the routine its putting all 3 lines (the original, and the two offset lines) on that layer. Can someone review it over and respond. Thanks

    Code:
    (defun C:OFF (/ pickEnt pickObj offDist)
      (vl-load-com)
      (setq offDist 0.0812)
      (while 
    (setq pickEnt (entsel))
        (cond ((and pickEnt (setq pickObj (vlax-EName->vla-Object (car pickEnt))) offDist)
               (vla-put-layer pickObj "STRUCTURE" )
           (vla-Offset pickObj offDist)
           (vla-Offset pickObj (- offDist))
           )
          ) ;_ end of cond
         ) ;_ end of while
       (princ)
      ) ;_ end of defun
    It is better to remain silent and be thought a fool, than to open your mouth and remove all doubt. -Abraham Lincoln

  2. #2
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,084

    Default

    Hi,

    Be careful to have the layer name "STRUCTURE" into your drawing before running the routine.

    Code:
    (defun c:Test (/ o s)
      (setq o 0.0812)
      (while (setq s (ssget "_+.:S:E:L" '((0 . "*LINE,CIRCLE,ARC,ELLIPSE"))))
        (foreach v (list o (- o))
          (vla-Offset (vlax-EName->vla-Object (ssname s 0)) v)
          (vla-put-layer (vlax-EName->vla-Object (entlast)) "STRUCTURE")
          )
        )
      (princ)
    ) (vl-load-com)

  3. #3
    Senior Member tmelancon's Avatar
    Computer Details
    tmelancon's Computer Details
    Operating System:
    Windows 7 Professional
    Computer:
    Dell Optiplex 7010
    CPU:
    i3-3220 Processor (Quad Core, 3.30GHz)
    RAM:
    8GB
    Graphics:
    HD2500 Graphics
    Primary Storage:
    500GB
    Secondary Storage:
    2TB External Backup
    Monitor:
    Dual Dell 27" Monitors!!
    Discipline
    Multi-disciplinary
    tmelancon's Discipline Details
    Occupation
    CAD Operations/Design
    Discipline
    Multi-disciplinary
    Details
    CAD Design, CAD Management, Project Management, ISO Drawings, Pressure Vessels, Inspection Reports, Data Analysis, Work Scope Recommendations, Troubleshooting, and anything else the boss needs to maximize efficiency. Also proficient in Electrical Engineering/Lighting Design and LEED Green Energy
    Using
    AutoCAD 2015
    Join Date
    Jun 2013
    Posts
    327

    Default

    I believe I have it now, just took me a little bit of reorganizing of where I was putting the step in and out of current layer.
    Code:
    (defun C:OFF (/ pickEnt pickObj offDist OLDLAYR *ERROR*)
      (vl-load-com)
    (defun *error* (msg)
        (if oldlayr (setvar "clayer" oldlayr))
        (if msg (prompt msg))
        (princ)
      )
      (setq offDist 0.0812)
      (while 
      (setq oldlayr (getvar "clayer"))
      (command "._-layer" "s" "STRUCTURE" "")
    (setq pickEnt (entsel))
        (cond ((and pickEnt (setq pickObj (vlax-EName->vla-Object (car pickEnt))) offDist)
               (vla-put-layer pickObj "STRUCTURE" )
           (vla-Offset pickObj offDist)
           (vla-Offset pickObj (- offDist))
               (vla-put-layer pickObj OLDLAYR )
               (command "._-layer" "s" oldlayr "")
           )
          ) ;_ end of cond
         ) ;_ end of while
       (princ)
      ) ;_ end of defun
    It is better to remain silent and be thought a fool, than to open your mouth and remove all doubt. -Abraham Lincoln

  4. #4
    Senior Member tmelancon's Avatar
    Computer Details
    tmelancon's Computer Details
    Operating System:
    Windows 7 Professional
    Computer:
    Dell Optiplex 7010
    CPU:
    i3-3220 Processor (Quad Core, 3.30GHz)
    RAM:
    8GB
    Graphics:
    HD2500 Graphics
    Primary Storage:
    500GB
    Secondary Storage:
    2TB External Backup
    Monitor:
    Dual Dell 27" Monitors!!
    Discipline
    Multi-disciplinary
    tmelancon's Discipline Details
    Occupation
    CAD Operations/Design
    Discipline
    Multi-disciplinary
    Details
    CAD Design, CAD Management, Project Management, ISO Drawings, Pressure Vessels, Inspection Reports, Data Analysis, Work Scope Recommendations, Troubleshooting, and anything else the boss needs to maximize efficiency. Also proficient in Electrical Engineering/Lighting Design and LEED Green Energy
    Using
    AutoCAD 2015
    Join Date
    Jun 2013
    Posts
    327

    Default

    Oh I just noticed you posted.. Wow well its obvious who has better lisp writing skills.. gosh I wish I was that good. I am getting better but definitely a noob when it comes to how I write. meehh I really wish I could further advance my lisp knowledge and programming knowledge. Thank you so much for your help it is greatly appreciate!!
    It is better to remain silent and be thought a fool, than to open your mouth and remove all doubt. -Abraham Lincoln

  5. #5
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,084

    Default

    Quote Originally Posted by tmelancon View Post
    Oh I just noticed you posted.. Wow well its obvious who has better lisp writing skills.. gosh I wish I was that good. I am getting better but definitely a noob when it comes to how I write. meehh I really wish I could further advance my lisp knowledge and programming knowledge. Thank you so much for your help it is greatly appreciate!!


    You are most welcome .

    Practice and practice to become experienced guy.

  6. #6
    Luminous Being BlackBox's Avatar
    Computer Details
    BlackBox's Computer Details
    Operating System:
    Windows 8.1 Professional, Server 2012 R2 Datacenter
    Computer:
    Dell Precision T3600
    CPU:
    Hex-Core Intel Xeon 3.2Ghz
    RAM:
    32GB
    Graphics:
    3GB NVIDIA Quadro K4000
    Primary Storage:
    2 x 240GB Samsung EVO SSD (RAID 0)
    Secondary Storage:
    1TB Western Digital VelociRaptor 10K RPM
    Monitor:
    Dual 24" Dell Ultrasharp Widescreen Monitors
    Discipline
    Civil
    BlackBox's Discipline Details
    Occupation
    Senior Civil Designer
    Discipline
    Civil
    Details
    Public/Private Land Development, Transportation, and Utilities.
    Using
    Civil 3D 2016
    Join Date
    Nov 2009
    Posts
    5,282

    Default

    Looks like you guys have been posting since I was pulled into a meeting - but I'll post this anyway.

    This will ensure that the dependent layer is available, handles some misc. entity overrides, supports multiple entity selection, and supports UNDO:

    Code:
    (defun c:FOO (/ *error* _Offset acDoc layerName left right ss)
    
      (defun *error* (msg)
        (if ss (vla-delete ss))
        (if acDoc (vla-endundomark acDoc))
        (cond ((not msg))                                                   ; Normal exit
              ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
              ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
        )
        (princ)
      )
    
      (defun _Offset (x dir layerName)
        (foreach y (vlax-invoke x 'offset dir)
          (vla-put-color y acbylayer)
          (vla-put-layer y layerName)
          (vla-put-linetype y "bylayer")
        )
      )
    
      (if (ssget "_:L" '((0 . "ARC,CIRCLE,ELLIPSE,*LINE")))
        (progn
          (vla-startundomark
            (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
          )
          (vla-add (vla-get-layers acDoc) (setq layerName "STRUCTURE"))
          (setq left  0.0812
                right (- 0.0812)
          )
          (vlax-for x (setq ss (vla-get-activeselectionset acDoc))
            (_Offset x left layerName)
            (_Offset x right layerName)
          )
        )
      )
    
      (*error* nil)
    )


    Cheers
    "Potential has a shelf life." - Margaret Atwood
    AutoCAD, and Civil 3D Certified Professional | Autodesk Authorized Developer
    Sincpac C3D ~ Exchange Apps ~ Autoloader ~ AutoCAD Security

  7. #7
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,879

    Default

    Like Black box I would use in the simple code version above (setvar "clayer" "Structure") rather than the long winded command layer method. The VLa-add is a good idea as if exists keeps going else adds. It would be a good library defun so only 1 line required in your code.

    Code:
    ; library defun to check if layer exists
    ; there would be a acdoc defun also
    (defun addlayer (layername / acdoc)
    (vla-startundomark
            (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
          )
          (vla-add (vla-get-layers acDoc) layerName )
    ) ; end defun
    
    ; code (addlayer "STRUCTURE")
    A man who never made mistakes never made anything

  8. #8
    Luminous Being BlackBox's Avatar
    Computer Details
    BlackBox's Computer Details
    Operating System:
    Windows 8.1 Professional, Server 2012 R2 Datacenter
    Computer:
    Dell Precision T3600
    CPU:
    Hex-Core Intel Xeon 3.2Ghz
    RAM:
    32GB
    Graphics:
    3GB NVIDIA Quadro K4000
    Primary Storage:
    2 x 240GB Samsung EVO SSD (RAID 0)
    Secondary Storage:
    1TB Western Digital VelociRaptor 10K RPM
    Monitor:
    Dual 24" Dell Ultrasharp Widescreen Monitors
    Discipline
    Civil
    BlackBox's Discipline Details
    Occupation
    Senior Civil Designer
    Discipline
    Civil
    Details
    Public/Private Land Development, Transportation, and Utilities.
    Using
    Civil 3D 2016
    Join Date
    Nov 2009
    Posts
    5,282

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by BIGAL View Post
    Like Black box I would use in the simple code version above (setvar "clayer" "Structure") rather than the long winded command layer method. The VLa-add is a good idea as if exists keeps going else adds. It would be a good library defun so only 1 line required in your code.
    *Tips hat* - Cheers, dude.



    The only thing I'd add, and this is my $0.02 (take from it what you like) - is to call *UndoMark from the calling routine, rather than within the sub-function(s); just makes more sense for the code I use here, YMMV.
    "Potential has a shelf life." - Margaret Atwood
    AutoCAD, and Civil 3D Certified Professional | Autodesk Authorized Developer
    Sincpac C3D ~ Exchange Apps ~ Autoloader ~ AutoCAD Security

Similar Threads

  1. Need Lisp for Offset command with layer change
    By rajeshmuthu in forum AutoLISP, Visual LISP & DCL
    Replies: 14
    Last Post: 1st Sep 2017, 06:45 pm
  2. offset to layer
    By michaeloureiro in forum AutoLISP, Visual LISP & DCL
    Replies: 15
    Last Post: 9th Dec 2013, 03:43 pm
  3. Offset lines create diffrent layers and specify offset distence
    By 121madhu in forum AutoLISP, Visual LISP & DCL
    Replies: 23
    Last Post: 7th Dec 2013, 02:52 pm
  4. Offset to layer on particular side and erase orignal object offset from
    By Baber62 in forum AutoLISP, Visual LISP & DCL
    Replies: 19
    Last Post: 15th Oct 2012, 03:20 pm
  5. Offset Plane Will Not Offset Correctly
    By Bill Tillman in forum Autodesk Inventor
    Replies: 2
    Last Post: 6th Jun 2011, 03:15 am

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