Jump to content

Recommended Posts

Posted

Dear Autodesk group members, specially all programmers i need your help on this topic (it will be great if any one can help me on same)

i am looking to create a LISP for my project need for AUTOCAD 2017.

 

I want to create a Rectangle in specific layer with customized command then i want to give L & W to that rectangle on run time, so that after completion/in mid of command i will get rectangle of required size, then once rectangle is created i want to get a popup message that autocad shall ask me to give Name of rectangle which i want to place by default in the center of rectangle created.

 

i want to do this for different rectangles to be created.

 

i created customized command to create specific rectangle layer current followed by i created rectangle using below code at the moment. I am not in touch with LISP writing for 10 yrs & forgot most of the things and my previous codes are not working in new version. Please can anyone help me on same. it will be a great help from you, thanking you in advance for your kind support on same. i need it urgently.

 

(defun _SetCLayer (layerName)

(if (tblsearch "layer" layerName)

(setvar 'clayer layerName)

(prompt

(strcat "\n** Layer \"" layerName "\" not found ** ")

)

)

(princ)

)

(defun c:ACDB () (_SetCLayer "AC_DB") (command "RECTANG" "")) - in this autocad is also giving some violations.

(defun c:ACON () (_SetCLayer "AIR_CON") (command "RECTANG"))

(defun c:FBAT () (_SetCLayer "BATTERY") (command "RECTANG"))

(defun c:FBEN () (_SetCLayer "BUILDING_ENVELOPE") (command "RECTANG"))

(defun c:FCAB () (_SetCLayer "CABINET") (command "RECTANG"))

(defun c:DCDB () (_SetCLayer "DC_DB") (command "RECTANG"))

(defun c:FDEF () (_SetCLayer "Defpoints") (command "RECTANG"))

(defun c:FPDI () (_SetCLayer "DIMENSIONS") (command "RECTANG"))

(defun c:FPDR () (_SetCLayer "DOORS") (command "RECTANG"))

(defun C:FFED () (_SetCLayer "FEEDER") (command "RECTANG"))

(defun c:FPLD () (_SetCLayer "FLOOR_LEGEND") (command "RECTANG"))

(defun c:IMGI () (_SetCLayer "Image") (command "RECTANG"))

(defun c:FOTR () (_SetCLayer "OTHER") (command "RECTANG"))

(defun c:FRAK () (_SetCLayer "RACK") (command "RECTANG"))

(defun c:FREF () (_SetCLayer "RECTIFIER") (command "RECTANG"))

(defun c:FTEX () (_SetCLayer "TEXT") (command "RECTANG"))

)

 

In past i used below command to give text, which is now not working

(defun C:ACDBT ()

(setq bldg_no (strcase (getstring "/n Type the ACDB NO: ")))

(setq bldgno (strcat "ACDB" bldg_no))

(polbldgno)

(command "clayer" "AC_DB" "" "text" fspt txtht angpts bldgno "")

)

 

So finally my requirement is for floor plans i have to create:

1. Rectangle in current specific layer where i should get pop-up to give L & W.

2. Text in the center of that rectangle "with pop up to enter only number after concatenated Specific text"

3. After creation of all rectangles i want to give dimension to all rectangles in on go by selecting them.

Posted

Dear Autodesk group members, specially all programmers i need your help on this topic (it will be great if any one can help me on same)

i am looking to create a LISP for my project need for AUTOCAD 2017.

 

I want to create a Rectangle in specific layer with customized command then i want to give L & W to that rectangle on run time, so that after completion/in mid of command i will get rectangle of required size, then once rectangle is created i want to get a popup message that autocad shall ask me to give Name of rectangle which i want to place by default in the center of rectangle created.

 

i want to do this for different rectangles to be created.

 

i created customized command to create specific rectangle layer current followed by i created rectangle using below code at the moment. I am not in touch with LISP writing for 10 yrs & forgot most of the things and my previous codes are not working in new version. Please can anyone help me on same. it will be a great help from you, thanking you in advance for your kind support on same. i need it urgently.

(defun _SetCLayer (layerName)
(if (tblsearch "layer" layerName)
(setvar 'clayer layerName)
(prompt
(strcat "\n** Layer \"" layerName "\" not found ** ")
)
)
(princ)
)
(defun c:ACDB () (_SetCLayer "AC_DB") (command "RECTANG" "")) - in this autocad is also giving some violations.
(defun c:ACON () (_SetCLayer "AIR_CON") (command "RECTANG"))
(defun c:FBAT () (_SetCLayer "BATTERY") (command "RECTANG"))
(defun c:FBEN () (_SetCLayer "BUILDING_ENVELOPE") (command "RECTANG"))
(defun c:FCAB () (_SetCLayer "CABINET") (command "RECTANG"))
(defun cCDB () (_SetCLayer "DC_DB") (command "RECTANG"))
(defun c:FDEF () (_SetCLayer "Defpoints") (command "RECTANG"))
(defun c:FPDI () (_SetCLayer "DIMENSIONS") (command "RECTANG"))
(defun c:FPDR () (_SetCLayer "DOORS") (command "RECTANG"))
(defun C:FFED () (_SetCLayer "FEEDER") (command "RECTANG"))
(defun c:FPLD () (_SetCLayer "FLOOR_LEGEND") (command "RECTANG"))
(defun c:IMGI () (_SetCLayer "Image") (command "RECTANG"))
(defun c:FOTR () (_SetCLayer "OTHER") (command "RECTANG"))
(defun c:FRAK () (_SetCLayer "RACK") (command "RECTANG"))
(defun c:FREF () (_SetCLayer "RECTIFIER") (command "RECTANG"))
(defun c:FTEX () (_SetCLayer "TEXT") (command "RECTANG"))
)

In past i used below command to give text, which is now not working
(defun C:ACDBT ()
(setq bldg_no (strcase (getstring "/n Type the ACDB NO: ")))
(setq bldgno (strcat "ACDB" bldg_no))
(polbldgno)
(command "clayer" "AC_DB" "" "text" fspt txtht angpts bldgno "")
)

So finally my requirement is for floor plans i have to create:

1. Rectangle in current specific layer where i should get pop-up to give L & W.

2. Text in the center of that rectangle "with pop up to enter only number after concatenated Specific text"

3. After creation of all rectangles i want to give dimension to all rectangles in one go by selecting them.

Posted

Write a defun that draws the rectang so rather than command "rectang" (Drawrectang) this should ask for bottom left point length and width. Here is a start dim as you go much easier than pick all afterwards. Just me I would use a menu or toolbar rather than all the c:defuns. With a menu can sub sub menus etc.

 

(defun drawrectang ( / pt pt2 len wid )
(setq pt (getpoint "please pick lower left"))
(setq len (getdist pt "Please enter length"))
(setq wid (getdist pt "Please enter width"))
(command "rectang" pt "D" len wid "")
(setq pt2 (polar pt 0.0 len)) ; 4 corner points
(setq pt3 (polar pt2 (/ pi 2.0) wid))
(setq pt4 (polar pt (/ pi 2.0) wid))
(setq ang (angle pt pt2))
(setq len (distance pt pt2))
(setq pt (polar ang (/ len 2.0)))
(command "text" pt "" "" (rtos len 2 2))
)
; do dims based on pt pt2 pt3 pt4

 

This can be used for your length and width input just look at sample for 2 items in code.

GETVALS.lsp

Posted

This will do a rectang add dims and label

 

; draw a rectang and remember the corners v's just draw a rectang
; by Alan H Feb 2017

; this defun would live in my library
(defun rectangcnrs ( / len wid )
(setq pt1 (getpoint "please pick lower left"))
(setq len (getdist pt1 "Please enter length")) 
(setq pt2 (polar pt1 0.0 len)) ; 4 corner points
(setq wid (getdist pt2 "Please enter width"))
(setq pt3 (polar pt2 pi2 wid))
(setq pt4 (polar pt3 pi len))
(command "rectang" pt1 pt3)
)

; program starts here
(defun c:rectdimtx ( / off oldang oldsnap  pt1 pt2 pt3 pt4 pt5)
(setq pi2 (/ pi 2.0)) ; global setting in my library lisp needed

(setq off 20) ; change this as required or ask for offset code

; remember old settings
(setq oldang (getvar 'angdir))
(setq oldsnap (getvar 'osmode))
(setq angunits (getvar 'aunits))
; make angles counterclockwise so angles work
; turn off osnaps just helps
(setvar 'angdir 0)
(setvar 'osmode 0)
(setvar 'aunits 3)

(rectangcnrs)

(command "_.dimaligned" pt2 pt3 (polar pt2 0.0 off))
(command "_.dimaligned" pt3 pt4 (polar pt4 pi2 off))
(setq ang (angle pt3 pt1))
(setq pt5 (polar pt1 ang (/ (distance pt1 pt3) 2.0)))
(command "text" pt5 "" ang (getstring "Enter text")) ; put this getstring in getvals using 3 lines len wid desc

(setvar 'angdir oldang)
(setvar 'osmode oldsnap)
(setvar 'aunits angunits)

) ;defun

Posted

This version uses a dcl for input.

 

; draw a rectang and remember the corners v's just draw a rectang
; by Alan H Feb 2017

; this defun would live in my library
(defun rectangcnrs ( / len wid )
(if (not AH:getval1)(Load "getvals")) ; loads getval 1-3
(setq pt1 (getpoint "please pick lower left"))
(ah:getval2 "Enter length" 5 4 "Enter height" 5 4)
(setq len (atof val1))
(setq wid (atof val2))
(setq pt2 (polar pt1 0.0 len)) ; 4 corner points
(setq pt3 (polar pt2 pi2 wid))
(setq pt4 (polar pt3 pi len))
(command "rectang" pt1 pt3)
)

; program starts here
(defun c:rectdimtx ( / off oldang oldsnap  pt1 pt2 pt3 pt4 pt5)
(setq pi2 (/ pi 2.0)) ; global setting in my library lisp needed

(setq off 20) ; change this as required or ask for offset code

; remember old settings
(setq oldang (getvar 'angdir))
(setq oldsnap (getvar 'osmode))
(setq angunits (getvar 'aunits))
; make angles counterclockwise so angles work
; turn off osnaps just helps
(setvar 'angdir 0)
(setvar 'osmode 0)
(setvar 'aunits 3)

(rectangcnrs)

(command "_.dimaligned" pt2 pt3 (polar pt2 0.0 off))
(command "_.dimaligned" pt3 pt4 (polar pt4 pi2 off))
(setq ang (angle pt1 pt3))
(setq pt5 (polar pt1 ang (/ (distance pt1 pt3) 2.0)))
(ah:getval1 "Enter string" 5 4)
(command "text" pt5 "" ang val1) ; put this getstring in getvals using 3 lines len wid desc

(setvar 'angdir oldang)
(setvar 'osmode oldsnap)
(setvar 'aunits angunits)

) ;defun

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