Jump to content

Insert Front..


mitchellrodhous

Recommended Posts

Hi,

 

If I get the insertion point anywere in the modelspace the lisp works correctly.

But wenn I want to click on an endpunt of excisting object in my modelspace I get an error.

 

Does anyone know wat could caused that?

ps1: it is going wrong wenn I try to use ip of an 3d solid! bij 2d objects it is going wel!

 

Thanks MR

 

 

(defun c:front ()
 ;define the function
 ;*
 ;Save System Variables
 (setq oldsnap (getvar "osmode"))
 ;save snap settings
 (setq oldblipmode (getvar "blipmode"))
 ;save blipmode setting
 ;*
 ;Switch OFF system Variables
 (setvar "osmode" 0)
 ;Switch OFF snap
 (setvar "blipmode" 0)
 ;Switch OFF Blipmode
 ;*
 ;get User Inputs
 (setq s (getdist "\nHowmuch Offset do you want? :"))
 ;Offset of you cabin front from the trunk

 (setq d (getdist "\nThickness of the front : "))
 ;Thickness of your front
 (setq h (getdist "\nHeight of you cabin : "))
 ;Input the Hight of you cabin
 (setq b (getdist "\nWidth of you cabin : "))
 ;Input the Width of you cabin
 ;*
 ;Get Insertion Point
 (setvar "osmode" 32)
 ;Switch ON snap
 (setq ip (getpoint "\nInsertion Point : "))
 ;get the insertion point
 (setvar "osmode" 0)
 ;Switch OFF snap

 (setvar "cmdecho" 0)

 ;*
;Start of Polar calculations
 (setq p2 (polar ip (dtr 0.0) 0))
 (setq p3 (polar ip (dtr 0.0) b))
 (setq p4 (polar p3 (dtr -90.0) d))
 (setq p5 (list (car p2) (cadr p2) (+ (caddr p2) h)))
 (setq p6 (list (car p5) (cadr p5) (- (caddr p5) 160)))
 (setq r1 (list (car p2) (cadr p2) (+ (caddr p2) s)))
 (setq p7 (polar p2 (dtr 0.0) s))
 (setq p8 (list (car p7) (cadr p7) (+ (caddr p7) s)))
 (setq p9 (polar r1 (dtr 0.0) b))
 (setq p10 (polar p9 (dtr 180.0) s))
 (setq p11 (list (car p7) (cadr p7) (+ (caddr p7) h)))
 (setq p12 (list (car p11) (cadr p11) (- (caddr p11) s)))
 (setq p13 (polar p10 (dtr -90.0) d))

 ;End of Polar Calculations
 ;*
 ;Start of Command Function
 (command "box" p8 p13 p12

) ;End Command
 ;End of Command Function
 ;Start of Command Function
 (command "-insert" "listscharnier" "_non" ip "" "" "0"
   "-insert" "listscharnier" "_non" p6 "" "" "0"
) ;End command
 ;End of Command Function
 ;*
 (setvar "osmode" 32)
 ;Switch ON snap
 ;*
 ;Reset System Variable
 (setvar "osmode" oldsnap)
 ;Reset snap
 (setvar "blipmode" oldblipmode)
 ;Reset blipmode
 ;*
 (princ)
 ;finish cleanly
 );end of defun

;*
;This function converts Degrees to Radians.
(defun dtr (x)
 ;define degrees to radians function
 (* pi (/ x 180.0))
 ;divide the angle bij 180 then
 ;mutiply the result by the constant PI
 ) ;End of function
;*
(princ) ;load cleanly
;*

Link to comment
Share on other sites

  • Replies 21
  • Created
  • Last Reply

Top Posters In This Topic

  • mitchellrodhous

    10

  • Hippe013

    9

  • MarcoW

    3

Top Posters In This Topic

Posted Images

To me it works, maybe some issue with the end point not being on the same elevation as the new front?

 

Bij mij werkt het... Ik weet het verder niet maar misschien heeft het met de Z positie te maken?

Link to comment
Share on other sites

Yes, I also think It has to do with the position of Z.

Only is theire a command I can set the position of Z from my lisp so It wil work.

Or maybe I can call this lisp file out of another lisp so it wil place the insertion point of this lisp in an point given by the other lisp?

 

"Ja ik denk ook dat het iets met de Z waarde te maken heeft.

Misschien is er dan een command dat ik de Z positie kan bepalen vanuit mijn lisp file...

Of misschien is het ook een mogelijkheid om deze lisp op te roepen vanuit een andere lisp? Dan kan ik het insertion point van deze lisp op een point, gegeven vanuit de andere lisp, bepalen?

°verwarrend°"

Link to comment
Share on other sites

I am sorry, can't help you further I am afraid... I am totally unaware of 3D capabilities within AutoCAD. Be patient, there are many amongst us that have the knowledge you need.

 

Translation not needed I think...

Link to comment
Share on other sites

I am sorry, can't help you further I am afraid... I am totally unaware of 3D capabilities within AutoCAD. Be patient, there are many amongst us that have the knowledge you need.

 

Translation not needed I think...

Somebody else who might know how to set it up?

Link to comment
Share on other sites

What error are you recieving? Can you post the block that your code inserts? I am finding that it all works except for not having the block to insert. I would suggest some changes to the code so that you could see what you are drawing as you enter the inputs...

Link to comment
Share on other sites

I am finding that it all works except for not having the block to insert.

 

Me to, I made a block myself, maybe I should not have done that...

Link to comment
Share on other sites

Hey!

 

Thanks for reply.

 

I attached the file scharnier.zip because it is an 3d Solid object.

 

The lisp file does work correctly, only If I play the lisp and pick my pickpoint on an 2d Object snappoint. But If I play the lisp in and pick an pickpoint from a 3d object It gives the result that the box it has to draw got an total different dimension/size.

I'll give you the code so you can see the commands

 

ps1: you can only play this lisp after you loaded the attachment once in acad otherwise he can't find the file...

 

ps2: Does somebody know how I can insert an block like in the attachment without load the block first?

 

 

 

(defun c:front ()
 ;define the function
 ;*
 ;Save System Variables
 (setq oldsnap (getvar "osmode"))
 ;save snap settings
 (setq oldblipmode (getvar "blipmode"))
 ;save blipmode setting
 ;*
 ;Switch OFF system Variables
 (setvar "osmode" 0)
 ;Switch OFF snap
 (setvar "blipmode" 0)
 ;Switch OFF Blipmode
 ;*
 ;get User Inputs
 (setq s (getdist "\Offset of the front:"))
 ;Hoeveel speling rondom de fronten

 (setq d (getdist "\nThickness of the front : "))
 ;Thickness of the front
 (setq h (getdist "\nHight of the front : "))
 ;Hight of the front
 (setq b (getdist "\nWidth of the front : "))
 ;Width of the front
 ;*
 ;Get Insertion Point
 (setvar "osmode" 32)
 ;Switch ON snap
 (setq ip (getpoint "\nInsertion Point : "))
 ;get the insertion point
 (setvar "osmode" 0)
 ;Switch OFF snap

 (setvar "cmdecho" 1)

 ;*
;Start of Polar calculations
 (setq p2 (polar ip (dtr 0.0) 0))
 (setq p3 (polar ip (dtr 0.0) b))
 (setq p4 (polar p3 (dtr -90.0) d))
 (setq p5 (list (car p2) (cadr p2) (+ (caddr p2) h)))
 (setq p6 (list (car p5) (cadr p5) (- (caddr p5) 160)))
 (setq r1 (list (car p2) (cadr p2) (+ (caddr p2) s)))
 (setq p7 (polar p2 (dtr 0.0) s))
 (setq p8 (list (car p7) (cadr p7) (+ (caddr p7) s)))
 (setq p9 (polar r1 (dtr 0.0) b))
 (setq p10 (polar p9 (dtr 180.0) s))
 (setq p11 (list (car p7) (cadr p7) (+ (caddr p7) h)))
 (setq p12 (list (car p11) (cadr p11) (- (caddr p11) s)))
 (setq p13 (polar p10 (dtr -90.0) d))

 ;End of Polar Calculations
 ;*
 ;Start of Command Function
 (command "ucs" "w" 
) ;End command
 (command "box" p8 p13 p12

) ;End Command
 ;End of Command Function
 ;Start of Command Function
 (command "-insert" "listscharnier" "_non" ip "" "" "0"
   "-insert" "listscharnier" "_non" p6 "" "" "0"
) ;End command
 ;End of Command Function
 ;*
 (setvar "osmode" 32)
 ;Switch ON snap
 ;*
 ;Reset System Variable
 (setvar "osmode" oldsnap)
 ;Reset snap
 (setvar "blipmode" oldblipmode)
 ;Reset blipmode
 ;*
 (princ)
 ;finish cleanly
 );end of defun

;*
;This function converts Degrees to Radians.
(defun dtr (x)
 ;define degrees to radians function
 (* pi (/ x 180.0))
 ;divide the angle bij 180 then
 ;mutiply the result by the constant PI
 ) ;End of function
;*
(princ) ;load cleanly
;*

 

Anyone know|?

scharnier.zip

Link to comment
Share on other sites

Ok, I did found out what is going wrong, but now I have to get an code to get it work.

 

Bij placing an object as box by using LISP you can run the LISP pomplete correctly if you are clicking in the modelspace. After al; If you click at an endpoint of an exciting SOLID object for your insertion point the lisp does'nt work correct.

I just started to create these lisp files and I am wondering if I could get an code so I can select an endpoint as my starting point and stil run correctly my lisp file... I will attach the lisp files,

 

ps1: It is an tip to also load my listscharnier to get an good running of the lisp.

 

Greet MR

front.LSP

Link to comment
Share on other sites

What are your typical dimensions that you enter for the front, width, thickness, etc.? Could you upload a dwg of what you are trying to achieve ( a final propduct)? In looking at your code I can't at this time see what would be wrong unless I know what you are trying to achieve. One thing I do see though is that the dtr function isn't really necessary. 0 degrees = 0 radians, 180 degrees = pi, -90 degrees = (* 1.5 pi). As far as inserting the block before loading you would have to have the code draw the block, create the block, and then insert. (as far as I know anyways)...

Link to comment
Share on other sites

I've reposted your code to suggest some minor changes.

 

 
(defun c:front2 ()

 ;Start of Save Settings
 (setq oldsnap (getvar "osmode"))
 (setq oldblipmode (getvar "blipmode"))
 ;end of Save Settings

 
 ;Start of Get User Input
 (setq s (getreal "\nOffset of your front from outside cabinet: "))
 (setq d (getreal "\nThickness of the Front: "))
 (setq h (getreal "\nHeight of the Front: "))
 (setq b (getreal "\nWidth of the Front: "))
 (setq ip (getpoint "\nInsertion Point: "))
 ;End of Get User Input
 (setvar "osmode" 0);Turn off snaps
 (setvar "cmdecho" 1); For debugging purposes???

 ;Start of Polar Calculations
 
 (setq p2 ip) ;ip = p2
 (setq p3 (polar ip 0 b)) ; From p2 to p3 = Width of the Front
 (setq p4 (polar p3 (* 1.5 pi) d)) ; From p3 to p4 = Thickness of the Front
 (setq p5 (list (car p2) (cadr p2) (+ (caddr p2) h))) ; p5 = x & y of p2 and z of p2 + Height of the Front
 (setq p6 (list (car p5) (cadr p5) (- (caddr p5) 160))) ; p6 = x & y of p5 and z of p5 - 160 units
 (setq r1 (list (car p2) (cadr p2) (+ (caddr p2) s))) ; r1 = x & y of p2 and z of p2 + Offset of your front from outside cabinet
 (setq p7 (polar p2 0 s)); From p2 to p7 = Offset of your front from outside cabinet
 (setq p8 (list (car p7) (cadr p7) (+ (caddr p7) s))); p8 = x & y of p7 and z of p7 + Offset of your front from outside cabinet
 (setq p9 (polar r1 0 b));From r1 to p9 = Width of the Front
 (setq p10 (polar p9 pi s)) ;From p9 to p10 = Offset of your front from outside cabinet
 (setq p11 (list (car p7) (cadr p7) (+ (caddr p7) h))); p11 = x & y of p7 and z of p7 + Height of the Front
 (setq p12 (list (car p11) (cadr p11) (- (caddr p11) s))); p12 = x & y of p11 and z of p11 - Offset of your front from outside cabinet
 (setq p13 (polar p10 (* 1.5 pi) d)) ;From p10 to p13 = Thickness of the Front
 ;End of Polar Caclulations

 
 (command "ucs" "w") ;Make sure that the ucs is in world???
 ;This should maybe be before the Get User Inputs???

 
 (command "box" p8 p13 p12)
 ;Create a 3d Solid using p8, p13 & p12

 
 (command "-Insert" "listscharnier" "_non" ip "" "" "0")
 (command "-Insert" "listscharnier" "_non" p6 "" "" "0")
 ;Insert the block at the ip (p2) & p6

 
 ;Start Reset Old Settings
 (setvar "osmode" oldsnap)
 (setvar "blipmode" oldblipmode)
 ;End Reset old Settings

 
 (princ "\nDone!") ;Let User Know Command is finished
 (princ) ; Finish Clean
 )
 
 

Link to comment
Share on other sites

See my attachment. After I create the cabinet like in the file I want to add my front. I want to give my offset of the cabinet then the hight of that cabinet and the width. Then I want to insert the front by click on the position were I placed an sphere. but then it isn't working;)

 

Regards MR

1.dwg

Link to comment
Share on other sites

I've had a chance to take a look at your dwg this morning. I believe your error comes in your polar computations. The following are changes that I have made. Try replacing the following in your code.

 

 
;Start Polar Computations
(setq p2 (polar ip 0 s))
(setq p3 (list (car p2) (cadr p2) (+ (caddr p2) s)))
(setq p4 (polar p3 (* 1.5 pi) d))
(setq p5 (polar p4 0 b))
(setq p6 (list (car p5) (cadr p5) (+ (caddr p5) h)))
(setq p7 (list (car ip) (cadr ip) (+ (- h 160) (caddr ip))))
;End Polar Computations

:Draw Box Using Points p3, p5 & p6
(command "box" p3 p5 p6)
;End Draw Box

;Insert Hinges Using Point ip & p7
(command "-insert" "listscharnier" "_non" ip "" "" "0"
   "-insert" "listscharnier" "_non" p7 "" "" "0"
)
;End Insert Hinges

 

P.S. The dtr function isn't neccessary...

Link to comment
Share on other sites

well I can create the front with my hingles but still can't click my ip on the corner of the cabinet.

If I click on the corner of an cabinet this lisp won't work.

 

did you tried to create it and click on the corner of the cabinet>?

 

Regards MR

Link to comment
Share on other sites

Well... What isn't working for you? With the changes that I made everything works fine ( with some adjustments to the INSUNITS).

I enter the distance for the offset, the thickness, the height, and then the width. I then click the corner where you had placed the sphere and everything falls right into place, Hinges and box. I'd Love to help you but I will need to know exactly what is not going right for you.

Link to comment
Share on other sites

MR,

 

I added code that searches for the name of the block and if it is not loaded then the user is prompted to find the file. I hope that this works for you...(it is working for me) Let me know how it goes.

 

Regards, Hippe013

 

 
(defun c:front ()
 ;Begin Save Settings
 (setq oldsnap (getvar "osmode"))
 (setq oldblipmode (getvar "blipmode"))
 ;End Save Settings
 ;Begin Set Settings
 (setvar "osmode" 0)
 (setvar "blipmode" 0)
 (command "ucs" "world")
 ;End Set Settings

 ;Begin User Input
 (setq s (getdist "\Offset of the front:"))=
 (setq d (getdist "\nThickness of the front : "))
 (setq h (getdist "\nHight of the front : "))
 (setq b (getdist "\nWidth of the front : "))
 (setvar "osmode" 32)
 (setq ip (getpoint "\nInsertion Point : "))
 ;End User Input

 ;Begin Set Settings
 (setvar "osmode" 0)
 (setvar "cmdecho" 1)
 ;End Set Settings

 ;Begin Polar Computations
 (setq p2 (polar ip 0 s))
 (setq p3 (list (car p2) (cadr p2) (+ (caddr p2) s)))
 (setq p4 (polar p3 (* 1.5 pi) d))
 (setq p5 (polar p4 0 b))
 (setq p6 (list (car p5) (cadr p5) (+ (caddr p5) h)))
 (setq p7 (list (car ip) (cadr ip) (+ (- h 160) (caddr ip))))
 ;End Polar Computations

 ;Begin Draw Box
 (command "box" p3 p5 p6)
 ;End Draw Box

 ;Begin Define blk-is-loaded
(defun blk_is_loaded (blk-name / blks cnt n I-Name ret )
 (vl-load-com)
 (setq blks (vlax-get-property (vlax-get-property (vlax-get-acad-object) 'ActiveDocument) 'Blocks))
 (setq cnt (vlax-get-property blks 'Count))
 (setq n 0)
 (repeat cnt
   (setq I-Name (vlax-get-property (vlax-invoke-method blks 'Item n) 'Name))
   (if (= blk-name I-Name)
(setq ret T)
     (progn
(setq n (+ n 1))
(setq ret nil))
     )
   )(vlax-release-object blks)
 ret
 )
 ;End Define blk-is-loaded
 ;Begin Determine if block is loaded
 ;***If block is not found user is directed to find the file else block is inserted***
 ;NOTE: No error trapping
 (if (not (blk_is_loaded "listscharnier"))
   (progn
     (setq blk-f (getfiled "Find listscharnier Block" "" "dwg" 0))
     (if (= blk-f nil)
(progn (princ "\nUser has Cancelled: Exiting.")
  (exit)))
     (command "-Insert" blk-f "_non" ip "" "" "0")
     (command "-Insert" blk-f "_non" p7 "" "" "0")
     )
   (command "-Insert" "listscharnier" "_non" ip "" "" "0"
     "-Insert" "listscharnier" "_non" p7 "" "" "0")
   )
 ;End Determine if block is loaded
 ;Begin Reset Old Settings
 (setvar "osmode" oldsnap)
 (setvar "blipmode" oldblipmode)
 ;End Reset Old Settings
 [color="Red"](princ (strcat "\nDimensions Entered for Front: \nOffset = " (rtos s 2 2) "\nThickness = " (rtos d 2 2) "\nHeight = " (rtos h 2 2)
      "\nWidth = " (rtos b 2 2) ) )[/color]
 (princ)
)

Link to comment
Share on other sites

One other issue that I am finding is that you need to open your scharnier.dwg and move the block "listscharnier" from the insert point to 0,0 and then set your INSUNITS to 4 in scharnier.dwg then save and then you need to make sure that your drawing INSUNITS are set to 4 as well. All should work then. :)

Link to comment
Share on other sites

Hey! Thanks for your bet to get this done wenn I take over your code I get as result the front stays low.... I dont know what it is. I attach an image.

hingle error.jpg

Link to comment
Share on other sites

Are you saying that the box isn't being drawn right? What are the dimensions that you enter for the Offset, Thickness, Height and Width? I've edited the above code (in red) to print to screen the dimensions that were entered.

Link to comment
Share on other sites

correct, I am taking over the complete code you changed.

Now after I load my lisp kast, I wil include as attachment, I will draw the cabinet by using the lisp kast. try to draw it.. than after I draw this cabinet I wil insert my front on this cabinet. well I use offset 3 than for hignt I click on the top corner on the cabinet and the bottom corner of the cabinet, for the widht I click on the left bottom corner and the right bottom corner, than click my insertion point on the left bottom corner...

I really not knowing why it draws the front that low....

 

Regards MR

kast.LSP

Link to comment
Share on other sites

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