AutoLISP Productivity Power

Similar documents
Networking AutoCAD for Control and Speed

AutoLISP for CAD Managers Robert Green Robert Green Consulting Group

Robert Green Robert Green Consulting

AutoLISP Tricks for CAD Managers Speaker: Robert Green

AutoLISP - Beyond the Crash Course Robert Green Robert Green Consulting Group

*.lsp Commands: + - * / setq setvar getvar getpoint defun command getstring appload vlide

Networking AutoCAD for Control and Speed

Course Title: Mastering the Visual LISP Integrated Development Environment (IDE)

Beyond AutoLISP Basics

Book IX is designed to help both AutoCAD and AutoCAD LT users

Chapter 28 Beyond AutoLISP Basics. Learning Objectives

Las Vegas, Nevada December 3-6, Course: Working with Custom menus in ADT

Mastering the Visual LISP Integrated Development Environment

The Anglemaker Program

Modeling Basics for 3D Printing Using AutoCAD

AUGI Tips and Tricks GD12-2. Donnia Tabor-Hanson - MossCreek Designs

CM6186-L - Autodesk AutoCAD Customization Boot Camp: Basics (No Experience Required)

Painless Productivity Programming with the Autodesk AutoCAD Action Recorder Revealed!

Autodesk Vault and Data Management Questions and Answers

Data Mining in Autocad with Data Extraction

Fusion 360 strategies for bridging Between digital and physical models

Script... Programming for Dummies. R. Yoshi Honda. What are Script files (.scr)

Creating Fills and Transparency in SketchBookk Designer

What s New in Autodesk V a ul t 20 18

Schedules Can t Do That in Revit 2017

Chapter 29 Introduction to Dialog Control Language (DCL)

Discover the DATA behind the Drawing Using A+CAD. Permission to copy

Autodesk Vault What s new in 2015

Converting Existing Specs and Catalogs for Use in Autodesk AutoCAD Plant 3D

AC6496 A Tribute to Attributes - Adding Intelligence to Your Drawings

GEN9638: Forensic CADology: When Good DWG Files Go Bad

Dynamic Blocks in AutoCAD 2006

Questions and Answers

AutoCAD Lynn Allen s Tips and Tricks

Learning Objectives. About the Speaker. So You Think Your Version is Enough? Jeanne Aarhus Aarhus Associates, LLC AC6405-V

Deploying Autodesk software the easy way Class ID: IT18200

Take design further. AutoCAD

Revit + FormIt Dynamo Studio = Awesome!

Design Visualization with Autodesk Alias, Part 2

Questions and Answers

AutoCAD 2009 Certification Exam Guide

Configurator 360 Hands-On Lab

Autodesk Revit Architecture 2011

Top 10 Reasons to Upgrade from AutoCAD 2000 to AutoCAD 2008

A case study in adopting Fusion 360 Hockey Skate Adapter

Top AutoCAD Customization Tips. Top. Customization Tips Every AutoCAD User Should Know. By Ellen Finkelstein.

Learn about the creation and naming of tools as well as palettes. Learn how to save and distribute palettes from a network location

SD Get More from 3ds Max with Custom Tool Development

A set of annotation templates that maybe used to label objects using information input in the data model mentioned above.

Confessions of an AutoCAD Evangelist who discovered BIM. Heidi Hewett AutoCAD Technical Marketing Manager

Sheet Set Manager: Plot or Publish a List of Sheets Instantly

What s New in Autodesk Inventor 2019

From Desktop to the Cloud with Forge

Sheet Metal Design: Understanding Corner Relief Design Flexibility

Dataset files Download the dataset file Inventor_Course_F1_in_Schools_Dataset.zip. Then extract the files, the default location is C:\F1 in Schools.

1.2 Adding Integers. Contents: Numbers on the Number Lines Adding Signed Numbers on the Number Line

DOSLib. DOS Library Programmer s Reference. Version 3.0

Speaker Name: Bill Kramer. Course: CP42-2 A Visual LISP Wizard's Into to Reactor Magic. Course Description

DV1673-L: The Decoding Lab ilogic Intermediate Session. Steve Olson Manager, Training Services for MESA Inc.

Features and Benefits

AutoCAD Certification Preparation, Part 2

Best Practices for Loading Autodesk Inventor Data into Autodesk Vault

Autodesk Software Grant for F1 in Schools Step by Step Instructions

Troubleshooting Revit Using Journal Files

Back to Flat Producing 2D Output from 3D Models

MA1451: Autodesk Configurator 360 Making It Easy to Create Web and Mobile Catalogs of Configurable Products

Las Vegas, Nevada, December 3 6, Speaker Name: Heidi Hewett. Course ID:

Tips & Techniques in Autodesk Inventor 2013/2014 PLTW - Wisconsin Dec. 10, 2013

Create Effective Instructions Basics and Everyday Workflows for Autodesk Inventor Publisher

Managing Content with AutoCAD DesignCenter

Blockbusters: Unleashing the Power of Dynamic Blocks Revealed!

Making AutoCAD better for architects.

Linking RISA Software with Revit 2017: Beyond the Basics

Program Validation & Data Management Using Autodesk Revit + drofus + an IFC Model Server

Basics of Using Lisp! Gunnar Gotshalks! BLU-1

Autodesk Revit Structure Autodesk

Lisp. Versions of LISP

PTC Windchill Tips and Tricks

What s New in Autodesk Inventor Publisher Autodesk

Frequently Asked Questions

Architectural Visualization Workflow in Autodesk Building Design Suite 2013

Autodesk User Group International AUGI Training Program (ATP)

Location, Location, Location: New Field Workflows for AutoCAD

VBScript: Math Functions

Asynchronous Interactions and Managing Modeless UI with Autodesk Revit API

Compatible with AutoCAD 2013 to 2018

Features and Benefits Summary

Autodesk Conceptual Design Curriculum 2011 Student Workbook Unit 2: Parametric Exploration Lesson 1: Parametric Modeling

Best Practices for Implementing Autodesk Vault

Fundamentals of ADS. Environment: Windows /Visual C++ Introduction

Working with AutoCAD in Mixed Mac and PC Environment

Lab: Supplying Inputs to Programs

Architectural Drafting Using AutoCAD Creating and Adjusting Tool Palettes

Because After all These Years I Still Don t Get it!

Data Synchronization: Autodesk AutoCAD Map 3D Enterprise, FME, and ESRI ArcGIS

Java Program Structure and Eclipse. Overview. Eclipse Projects and Project Structure. COMP 210: Object-Oriented Programming Lecture Notes 1

Created by John Helfen. Edited by Janice Miller. Autodesk, Inc.

Las Vegas, Nevada, December 3 6, Speaker Name: dave espinosa-aguilar. Course Title: Fundamentals of AutoLISP.

AutoCAD Electrical: Advanced Productivity

SD Sparring with Autodesk ObjectARX Round 1 Stepping into the Ring

Transcription:

AutoLISP Productivity Power Robert Green CAD-Manager.com

Quick bio Mechanical engineer turned computer geek Private consultant since 1991 AutoLISP programmer since the beginning Focusing on CAD standardization, customization and management Cadalyst Magazine contributing editor 14 year AU speaker rgreen@cad-manager.com

Some fundamentals LISP LISt Processor Should you still use LISP? Everything is in lists

Should we still use AutoLISP? Yes! AutoLISP is still very valid! A HUGE base of LISP code exists LISP shareware is abundant LISP does many things very easily as compared to VB/VBA It is great for controlling AutoCAD configurations You don t have to know much to get results

Key files and why they matter LSP Load in order What to mess with What not to!

All those wacky file names ACAD20XX.LSP (system file XX is version) ACAD.LSP (This is your file) ACAD20XXDOC.LSP (system file - XX is version) ACADDOC.LSP (This is your file) CUINAME.MNL (loads with CUI) So what does it all mean?

What do they do, where they live They load on startup of AutoCAD They load in a certain order (listed on previous slide) Some have code in them and some don t (ACADDOC.LSP and ACAD.LSP don t as an example) They reside in the SUPPORT folder

So what should I do Use ACADDOC.LSP to get started You create your own ACADDOC.LSP It loads with every new drawing Put in in the SUPPORT folder and start hacking away If you mess up too bad, just delete!

Make sure it works Create ACADDOC.LSP Load from network? Verify operation

Find the support folder Use OPTIONS to find the folders

Add a network folder Use OPTIONS to add it

Create the file Use Notepad not Word! Use (prompt \nacaddoc.lsp loaded. ) as text

Save the file To the SUPPORT folder Use ACADDOC.LSP as the name

Alternately You can use APPLOAD to load files You can use STARTUP SUITE to load at each start

Syntax Basics Lists and Arguments Rules of AutoLISP Accessing the command line Special characters

Lists and Arguments (+ 20 30) Here the + is a FUNCTION and the two numbers are ARGUMENTS (command line 0,0 1,1 ) Here COMMAND is the function, all others are ARGUMENTS (getvar dimscale ) Which is the function? The argument?

The Command Line How would you work normally? Draw a line between two user points Type in LINE to start the line command Click POINT for first point location Click POINT for second point location Type in ENTER to halt the command In AutoLISP: (command line pause pause ) PAUSE instruction waits for the user The is equal to hitting the ENTER key. Why? Because that s they way it is

Some Rules For every ( there is an equal and opposite ) Like this: (setq A 3.0) Not like this: (setq A 3.0)) or (setq A 3.0 Same goes for quote marks! Like this: (setq name Robert Green ) Not like this: (setq name Robert Green) (setq name Robert Green ) For every function there is precisely one set of parens Like this: (+ 3 5) Not like this: ((+ 3 5)) When formatting numbers always avoid invalid dotted pairs Like this: (setq A 0.5) Not like this: (setq A.5)

What s Going On Here? (command viewres y 5000 ) (command -color BYLAYER ) (command -linetype set BYLAYER ) (command menu menuname.cuix ) (command viewres y pause) That s not so bad intuitive actually

Syntax Basics Named variables System variables Data types

Lists and embedded lists illustrated Standard AutoLISP Result 8 + 4 (+ 8 4) 12 8 + 2.3 (+ 8 2.3) 10.3 5 4 (/ 5 4) 1 (8 + 4) * 3 (* (+ 8 4) 3) 36 (3.0 * 5.0) 4.0 (/ (* 3.0 5.0) 4.0) 3.75 ((4 + 4) * 3) 2 (/ (* (+ 4 4) 3) 2) 12

SETQ (SET equal) To create the variable MYNAME and set it with your proper name as a value do this: (setq MYNAME Robert Green ) To store a system variable for DIMSCALE do this: (setq OLD_DIMSCALE (getvar dimscale )) Which uses embedded lists?

SETVAR (SET VARiable) To set the system variable for the fillet radius to 0.25 do this: (setvar filletrad 0.25) To set the system variable for expert status do this: (setvar expert 5) To set the system variable for dimension style do this: (setvar dimstyle am_ansi )

Storing variables and data types (setq VALUE 12.7) real number (setq VALUE 1) integer number (setq VALUE Happy ) string variable (setvar filletrad 0.25) real (setvar expert 5) Integer (setvar dimstyle am_ansi ) - string Make sure you input the data the variable needs

Call outside programs To invoke a browser do this: (command browser file goes here ) To invoke an app: (startapp C:\folder\progname.exe )

User functions Speed for the user Lower support for you A win-win scenario Let s put everything we ve learned into action to build some functions.

User Function Examples (defun C:ZA () (command.zoom a ) (princ) )

User Function Examples (defun C:ZA () (command.zoom a ) (princ) )

User Function Examples (defun C:VR () (command viewres y 5000 ) ) * Note that I left out PRINC? (defun C:BL () (command -color BYLAYER ) (command -linetype set BYLAYER ) (princ) )

Fillet Zero Function Fillet Zero (defun c:fz () (setvar filletrad 0.0) (command.fillet pause pause) (princ) ) * What have I not done in this function?

Improved Fillet Zero (defun c:fz () (setq old_filletrad (getvar filletrad )) (setvar filletrad 0.0) (command.fillet pause pause) (setvar filletrad old_filletrad) (princ) ) * Note how we store and recall the FILLETRAD so the function puts things back the way they were!

Auto Purge Function Auto Purge (defun c:atp () (command -purge a * n.qsave ) (princ) ) (defun c:atp () (command -purge b * n.qsave ) (princ) )

More Bits and Bytes Undefine Dot form Redefine Alerts CMDECHO

Undefining (command.undefine LINE ) (command.undefine TORUS ) Don t want them messing with a command? Just undefine it Now you can SUBTRACT from the AutoCAD Command set in your ACADDOC.LSP file.

The DOT form Invoke commands like this:.line Note the dot. character? This allows you to invoke a command whether it has been undefined or not! This is our little secret right...

Redefining (command.redefine LINE ) (command.redefine TORUS ) Want to be sure that a command is active? Just redefine it Now you can UNSUBTRACT from the AutoCAD Command set with ease.

Undefining revisited What if your users find out about REDEFINE and start REDEFINING your UNDEFINES? Just undefine the redefine like this: (command.undefine REDEFINE ) That ll stop users from redefining

Redefining You can undefine a command and redefine it like this: (command.undefine TORUS ) (defun C:TORUS () (alert Don t use that command! ) (princ) ) Now you do whatever you want!

What Does This Do? (command.undefine QSAVE ) (defun c:qsave () (command -purge b * n ) (command.qsave ) (princ) )

Alerting the user You can send a message to the user like this: (alert Message goes here )

Command echo (CMDECHO) Run in STEALTH mode like this: (defun C:BL () (setvar cmdecho 0) (command -color BYLAYER ) (command -linetype set BYLAYER ) (setvar cmdecho 1) (princ) ) * SETVAR is on or off so no need to store it s value

Points and Sets How do points work? How can we work with object sets?

Get a set like this (setq user_set (ssget \nselect objects for movement: )) You now have a set stored in a variable Note the \n prompting to the user

Get some points like this (setq from_point (getpoint \nselect point to move objects FROM: )) (setq to_point (getpoint \nselect point to move objects TO: )) You now have two 3D points stored in variables Note the \n prompting to the user

Now take action like this (command.move user_set from_point to_point) You are now moving the set from the first point to the second point The user doesn t have to interact with MOVE Why do we have a in there

What would this do (defun c:mm () (setq user_set (ssget \nselect objects for movement: )) (setq from_point (getpoint \nselect point to move objects FROM: )) (setq to_point (getpoint \nselect point to move objects TO: )) (command.move user_set from_point to_point) (princ) )

Adding in Numbers Obtain numbers: GETREAL Real numbers GETINT Integer numbers How can we work with object sets now?

What would this do (defun c:mr () (setq user_set (ssget \nselect objects for move/rotate: )) (setq rotate_angle (getreal \ninput rotation angle: )) (setq from_point (getpoint \nselect point to move objects FROM: )) (setq to_point (getpoint \nselect point to move objects TO: )) (command.move user_set from_point to_point) (command.rotate user_set to_point rotate_angle) (princ) )

More Bits and Bytes Loading programs Loading CUIx files Centralized loading VLIDE environment Compiling

Load a CUI like this (command menu c:\\path\\cuiname.cuix ) Note: Not MENULOAD but MENU

VLIDE environment You can write code in the VLIDE window like this:

Compile your code Use the VLIDE environment like this: (vlisp-compile st c:\\test\\myprog.lsp ) You ll get MYPROG.FAS as a result

Load compiled code Use a LOAD statement like this: (load c:\\test\\myprog.fas ) Now your LSP code is secure! Be sure not to lose your LSP file though!

Centralizing AutoLISP Code CAD Managers rejoice! Keep you code in a single network location and load it every time users start up. Need to change code? Just change the master copy on the network!

Put this in the ACADDOC.LSP file (if (findfile "x:\\autolisp\\utils1.lsp") (load "x:\\autolisp\\utils1.lsp")) ) Network loaded programs are the way to go for convenience. This assumes a network X drive Note the \\ where a \ would normally be

Put this in the ACADDOC.LSP file (if (findfile "x:\\autolisp\\utils1.fas") (load "x:\\autolisp\\utils1.fas")) ) Network loaded compiled programs are the way to go for security. This assumes a network X drive Again, note the \\ where a \ would normally be

AutoLISP Productivity Power Robert Green CAD-Manager.com

Autodesk, AutoCAD* [*if/when mentioned in the pertinent material, followed by an alphabetical list of all other trademarks mentioned in the material] are registered trademarks or trademarks of Autodesk, Inc., and/or its subsidiaries and/or affiliates in the USA and/or other countries. All other brand names, product names, or trademarks belong to their respective holders. Autodesk reserves the right to alter product and services offerings, and specifications and pricing at any time without notice, and is not responsible for typographical or graphical errors that may appear in this document., Inc. All rights reserved.