Jump to content

Recommended Posts

Posted (edited)

Hi can someone help me with this lisp (CAD2010).

It is not mine - I downloaded it but would like it to be modified a little bit.

I want to select a layer named "TL - LD - Scanlight Interconnecting Leads"

I then want the lisp to label all the lines on this layer with their dimension and place these dimensions on a new layer labelled "TL - LD - Scanlight Interconnecting Dimension".

This will enable us to turn off and on the dim's as we have a lot more manipulation to do.

I would like the text height to be CONSTANT at 50 and the offset to be 75

This lsp has a prefix option that i would like set to ">" outside the dimension (constant to).

All i want the operator to do is type "SCANLINE" in CAD and everything else is done.

I would also like there to be no markers (ie the point style set to nothing).

I have tried to do this myself but keep breaking the code!!

 

Thank-you in advance

The LISP is below

 

 
; +-------+---------+---------+-----SCANLINE.lsp----+---------+--------+--------+ ;
(vl-load-com)
(defun C:SCANLINE (/ acsp adoc ang der ent gap midp mtx oid pline pref txp txt)
 (or adoc
     (setq adoc
     (vla-get-activedocument
       (vlax-get-acad-object)
       )
    )
     )
 (if (and
(= (getvar "tilemode") 0)
(= (getvar "cvport") 1)
)
   (setq acsp (vla-get-paperspace adoc))
   (setq acsp (vla-get-modelspace adoc))
   )
(if (setq ent (entsel "\nSelect polyline >>"))
   (progn
(setq oid (vla-get-objectid
    (setq pline (vlax-ename->vla-object
      (car ent))))
     )
(setq midp (vlax-curve-getclosestpointto pline
     (vlax-curve-getpointatdist pline
       (/ (vla-get-length pline) 2)))
     )
(vlax-invoke acsp 'AddCircle midp 2.0)
(setq der (vlax-curve-getfirstderiv pline
                       (vlax-curve-getparamatpoint pline midp)))
(if (zerop (cadr der))
          (setq ang (/ pi 2))
          (setq ang (- pi (atan (/ (car der) (cadr der)))))
        )
(initget 6)
(setq hgt (getdist "\nEnter text height <5.0>: "))
(if (not hgt)(setq hgt 5.))
(initget 6)
(setq gap (getdist "\nEnter distance of the text offset <2.5>: "))
(if (not gap)(setq gap 2.5))
(setq txp (polar midp ang gap))
(setq pref (getstring T "\nEnter label prefix <920>: "))
(if (eq "" pref)(setq pref "920"))
(setq pref (strcat pref " ("))
(setq txt (strcat pref
"%<[url="file://\\AcObjProp"]\\AcObjProp[/url] Object(%<[url="file://\\_ObjId"]\\_ObjId[/url] "
   (itoa oid)
   ">%).Length [url="file://\\f"]\\f[/url] \"%lu2%pr2\">% m)");--> number of decimals = 2
     )
(setq mtx (vlax-invoke acsp 'AddMText txp 0.0 txt)
       )
(setq ang (- ang (/ pi 2)))
(setq ang (cond
  ((> pi ang (/ pi 2))(- pi ang))
  ((> (* pi 1.5) ang pi)(- ang pi))
  ((> (* pi 2) ang (* pi 1.5))(- (* pi 2) ang))
   (T ang))
 )
(vlax-put mtx 'AttachmentPoint 5 )
(vlax-put mtx 'InsertionPoint txp)
(vlax-put mtx 'Height hgt)
(vlax-put mtx 'Rotation ang)
(vla-update mtx)
)
 )
 (princ)
   )
(princ "\n Start command with SCANLINE ...")
(princ)
; +---------+---------+---------+---------+---------+---------+---------+ ;

Edited by rkmcswain
add CODE tags
Posted
Hi can someone help me with this lisp (CAD2010).

It is not mine - I downloaded it but would like it to be modified a little bit.

 

 

I think this may qualify as the 'Understatement of the day'.

 

I do not mean to be rude, but you haven't received any help yet, because your request stops just short of treating CADTutor like a fast food drive-thru (which it is not). This is a place for the sharing of knowledge... the only thing you'll get 'your way', is code that you write yourself.

 

In the future, you may get a more timely response if you show some work first. There's nothing wrong with being new to programming, or even not understanding how to do something (we all started somewhere), but nobody (no matter your experience) likes a leach.

 

 

I have tried to do this myself but keep breaking the code!!

 

 

I'd like to help you, so please post some examples of your attempts, so myself or someone else can better advise you.

 

Just so you don't feel that I am in any way dismissing you, or your request for help, here's a couple of 'carrots' for you to consider:

 

I want to select a layer named "TL - LD - Scanlight Interconnecting Leads"

 

(if (and (tblsearch "layer" (setq layerName "TL - LD - Scanlight Interconnecting Leads"))
        (setq ss (ssget "_x" (list (cons 8 layerName)))))
 ;; ...code
 )

 

 

 

I then want the lisp to label all the lines on this layer with their dimension and place these dimensions on a new layer labelled "TL - LD - Scanlight Interconnecting Dimension".

 

(vlax-put mtx 'layer "TL - LD - Scanlight Interconnecting Dimension")

 

 

Hope this helps!

Posted (edited)

Thank-you Render-Man for your reply -

At least now I understand why my post was inapropriate - but for somebody who has had no training on CAD and only started using it 6 months ago at 33 - some of this is a little french to me!

 

I believe i have a mathmatical brain and can understand logic quiet well - its just the more I read about LISP the more I get confussed with the parameters and orders and reverse logic.

 

Our company is not the best for CAD and I am already more advanced that fellow users - just because I want to know how things work.

I am not trying to leach information and skills that I realise are valuable - I am also not looking to pass work off as my own - I have requested training at work - but non is available.

I am just trying to improve things and the way we work - as a lot of errors are being produced and its frustrating as I know with a bit of investment and the company could remove them.

 

My start and end point to this would have been to compare the original documnet (LISP) file with the new and then look at what changes were made and how they have affected the code.

Then for similar functions I would hopefully have been able to produce a working LISP.

 

I have tried to replace the variables within the code but did not know how to change orders.

If you can refer me to a book or webpage that could help - I will gladly go away and research.

I have so many questions it would be crazy to write them all and hoped that a pre and post way would probably answer most of them without bothering people.

Is there a way of writing the codes and a list of the constants!

At this stage I do not understand the pre-fixes and their application ie. vlax - getvar etc

Also how do i preset the attributes instead of "steq hgt" and (getdist ...

do i just remove the (getdist..

and then presumably use a command to set the height - set hgt 50

 

The problem i had is that i have so many questions i don't know where to start !

I will attach the LISP and write in red my questions - I hope that you can see I am interested in learning about these fuctions and how they work!

 

Thank-you anyway for replying

 

 


[size=3]; +-------+---------+---------+-----SCANLINE.lsp----+---------+--------+--------+ ;[/size]
[size=3](vl-load-com)[/size]
[size=3](defun C:SCANLINE (/ acsp adoc ang der ent gap midp mtx oid pline pref txp txt)[/size]
[color=red][size=3]Does above set the variables for this lisp[/size][/color]
[size=3]  (or adoc[/size]
[size=3]      (setq adoc[/size]
[size=3]                 (vla-get-activedocument[/size]
[size=3]                   (vlax-get-acad-object)                                           [/size]
[size=3]                   )[/size]
[size=3]                )[/size]
[size=3]      )[/size]
[size=3]  (if (and[/size]
[size=3]            (= (getvar "tilemode") 0)           [color=red]?[/color][/size]
[size=3]            (= (getvar "cvport") 1)              [color=red]?[/color][/size]
[size=3]            )[/size]
[size=3]    (setq acsp (vla-get-paperspace adoc))[/size]
[size=3]    (setq acsp (vla-get-modelspace adoc))[/size]
[size=3]    )[/size]

[size=3](if (and (tblsearch "layer" (setq layerName "TL - LD - Scanlight Interconnecting Leads"))[/size]
[size=3]         (setq ss (ssget "_x" (list (cons 8 layerName)))))[/size]
[size=3]  ;; ...code                                                         [/size]
[color=red][size=3]Can you select the layer then all polylines after - just incase someone has put the wrong thing on this layer[/size][/color]
[size=3]  )[/size]

[size=3](if (setq ent (entsel "\nSelect polyline >>"))        [color=red]I need to select all polylines “nSelect ..[/color][/size]
[size=3]    (progn[/size]
[size=3](setq oid (vla-get-objectid[/size]
[size=3]                (setq pline (vlax-ename->vla-object[/size]
[size=3]                  (car ent))))[/size]
[size=3]      )[/size]
[size=3](setq midp (vlax-curve-getclosestpointto pline[/size]
[size=3]                 (vlax-curve-getpointatdist pline[/size]
[size=3]                   (/ (vla-get-length pline) 2)))[/size]
[size=3]      )[/size]
[size=3](vlax-invoke acsp 'AddCircle midp 2.0) [color=red]- don’t need this can I just remove it[/color][/size]
[size=3](setq der (vlax-curve-getfirstderiv pline[/size]
[size=3]                        (vlax-curve-getparamatpoint pline midp)))[/size]

[size=3](if (zerop (cadr der))[/size]
[size=3]           (setq ang (/ pi 2))[/size]
[size=3]           (setq ang (- pi (atan (/ (car der) (cadr der)))))[/size]
[size=3]         )[/size]
[size=3](initget 6)[/size]
[size=3](setq hgt (getdist "\nEnter text height <5.0>: ")) [color=red]- can this just be (set hgt 50))[/color][/size]
[size=3](if (not hgt)(setq hgt 5.))[/size]
[size=3](initget 6)                                                                      [color=red]- what is (initget 6) ??[/color][/size]
[size=3](setq gap (getdist "\nEnter distance of the text offset <2.5>: ")) [/size]
[color=red][size=3]- can this be (setq gap 75)[/size][/color]
[size=3](if (not gap)(setq gap 2.5))                                            [color=red]- can I delete these[/color][/size]
[size=3](setq txp (polar midp ang gap))[/size]

[size=3](setq pref (getstring T "\nEnter label prefix <920>: ")) [/size]
[size=3](if (eq "" pref)(setq pref "920"))                         [color=red]can all this just be :-[/color][/size]
[size=3](setq pref (strcat pref " ("))                                            [color=red](setq pref (strcat pref “>(“))[/color][/size]
[size=3](setq txt (strcat pref                                                      [color=red]I want the prefix to be a >[/color][/size]
[size=3]"%<\\AcObjProp Object(%<\\_ObjId "[/size]
[size=3]                          (itoa oid)[/size]
[size=3]                          ">%).Length \\f \"%lu2%pr2\">% m)");--> number of decimals = 1[/size]
[size=3])                                                                                                                             [/size]
[color=red][size=3]I want it to only 1 decimal place ie 7.4m[/size][/color]

[size=3](setq mtx (vlax-invoke acsp 'AddMText txp 0.0 txt)[/size]
[size=3]                   )[/size]
[size=3](setq ang (- ang (/ pi 2)))[/size]
[size=3](setq ang (cond                                     [/size]
[size=3]              ((> pi ang (/ pi 2))(- pi ang))[/size]
[size=3]              ((> (* pi 1.5) ang pi)(- ang pi))[/size]
[size=3]              ((> (* pi 2) ang (* pi 1.5))(- (* pi 2) ang))[/size]
[size=3]               (T ang))[/size]
[size=3]                        )[/size]
[size=3](vlax-put mtx 'AttachmentPoint 5 )[/size]
[size=3](vlax-put mtx 'InsertionPoint txp)[/size]
[size=3](vlax-put mtx 'Height hgt)[/size]
[size=3](vlax-put mtx 'Rotation ang)[/size]
[size=3](vla-update mtx)[/size]
[size=3](vlax-put mtx 'layer "TL - LD - Scanlight Interconnecting Dimension") - [color=red]does this go here?[/color][/size]
[size=3])[/size]
[size=3]  )[/size]
[size=3]  (princ)[/size]
[size=3]    )[/size]
[size=3](princ "\n Start command with SCANLINE ...")[/size]
[size=3](princ)[/size]
[size=3]; +---------+---------+---------+---------+---------+---------+---------+ ;[/size]
Edited by Tiger
added code tags
Posted

Might I suggest Afralisp.net as a good place to start.

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