Create a Dashed line using two endpoints

Create a Dashed line using two endpoints

Anonymous
Not applicable
1,650 Views
10 Replies
Message 1 of 11

Create a Dashed line using two endpoints

Anonymous
Not applicable

I am looking for a code that will insert a dashed line that spans the distance between two predetermined endpoints but am unsure what this code would look like, currently I have a small code for insertion of a line: (command "line" "First point" "Second point" "") but I am unsure how to make this code insert a dashed line instead of the solid line it is inserting currently. Any help is appreciated!

0 Likes
Accepted solutions (1)
1,651 Views
10 Replies
Replies (10)
Message 2 of 11

dlanorh
Advisor
Advisor
Is "Dashed" Linetype loaded?

I am not one of the robots you're looking for

0 Likes
Message 3 of 11

Anonymous
Not applicable

yes it is

0 Likes
Message 4 of 11

dlanorh
Advisor
Advisor

This function will do that

 

(defun makeline (s_pt e_pt lyr)
  (entmakex (list
              '(000 . "LINE")
              '(100 . "AcDbEntity")
              '(100 . "AcDbLine")
              (cons 10 s_pt)
              (cons 11 e_pt)
              (cons 8 lyr)
              '(6 . "DASHED")
            )
  )
);end_defun

It is called like this (makeline start_point end_point layer). Brackets are not optional, but red layer items are optional (if you just want it on the current layer), if you don't want them remove the red items.

 

Or did you want to select the points

I am not one of the robots you're looking for

0 Likes
Message 5 of 11

Anonymous
Not applicable

im unsure if I am placing my point variables in the incorrect spots but when running this lisp it keeps returning an error that is stating I have too few arguments. If the endpoint variables I am using are labelled as "bip" and "ohd" am I placing these in the wrong place within the code?

(defun c:makeline (bip ohd)
(entmakex (list
'(000 . "LINE")
'(100 . "AcDbEntity")
'(100 . "AcDbLine")
(cons 10 bip)
(cons 11 ohd)
'(6 . "DASHED2")
)));end_defun

 

P.S. I apologize I am relatively new to auto lisp and still learning some of the ropes

0 Likes
Message 6 of 11

dlanorh
Advisor
Advisor
Accepted solution


@Anonymous wrote:

im unsure if I am placing my point variables in the incorrect spots but when running this lisp it keeps returning an error that is stating I have too few arguments. If the endpoint variables I am using are labelled as "bip" and "ohd" am I placing these in the wrong place within the code?

(defun c:makeline (bip ohd)
(entmakex (list
'(000 . "LINE")
'(100 . "AcDbEntity")
'(100 . "AcDbLine")
(cons 10 bip)
(cons 11 ohd)
'(6 . "DASHED2")
)));end_defun

 

P.S. I apologize I am relatively new to auto lisp and still learning some of the ropes


If you want to run it from the command line then

 

(defun c:makeline ( / s_pt e_pt ent)
  (setq s_pt (getpoint "\nSelect Line Start Point : ")
        e_pt (getpoint "\nSelect Line End Point : ")
        ent (entmakex (list
                        '(000 . "LINE")
                        '(100 . "AcDbEntity")
                        '(100 . "AcDbLine")
                        (cons 10 s_pt)
                        (cons 11 e_pt)
                        '(6 . "DASHED")
                      )
            )
  );end_setq
);end_defun

Here you will need to select the start and end points on screen

 

If you already have the start and end points saved in variables, then load the below

 

(defun makeline (s_pt e_pt)
(entmakex (list
'(000 . "LINE")
'(100 . "AcDbEntity")
'(100 . "AcDbLine")
(cons 10 s_pt)
(cons 11 e_pt)
'(6 . "DASHED2")
)));end_defun

This can be called from the command line like this

(makeline bip ohd)

This is a function and doesn't have a "c:" preceding the command name and so must be included in brackets

bip and ohd must be lists of three elements (list x y z) x coord y coord and z (level) coord.

I am not one of the robots you're looking for

Message 7 of 11

CodeDing
Advisor
Advisor

@dlanorh 

Personally, it's the little details that stand out to me 😉

(defun c:makeline ( / s_pt e_pt ent)
  (initget 1) (setq s_pt (getpoint "\nSelect Line Start Point : "))
  (initget 1) (setq e_pt (getpoint s_pt "\nSelect Line End Point : "))
  (setq ent (entmakex (list '(0 . "LINE") '(100 . "AcDbEntity") '(100 . "AcDbLine")
			    (cons 10 s_pt) (cons 11 e_pt) '(6 . "DASHED")
		      );list
	    );entmakex
  );setq
  (princ)
);defun

Best,

~DD

0 Likes
Message 8 of 11

hak_vz
Advisor
Advisor

@dlanorhhas pointed all what is necessary to entmake a line. Good practice would be (at least I see it that way) to have a predefined layer with all attributes already set (linetype, color, lineweigth .....). Newly created object will then inherit all those attributes from layer definition. Then you don't have to think if linetype definition is loaded and so on... 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 9 of 11

Anonymous
Not applicable

I see what you were saying earlier, thank you for the help it is very much appreciated!

0 Likes
Message 10 of 11

ronjonp
Advisor
Advisor

Agreed about the little details. FWIW .. I'd use (If (and rather than initget so you don't have to {esc} out of the program.

Maybe also check that dashed is actually loaded since that seems to be a key part of this intricate routine 🙂

(defun c:makeline (/ s_pt e_pt)
  (if (tblobjname "ltype" "DASHED")
    (while (and	(setq s_pt (getpoint "\nSelect Line Start Point : "))
		(setq e_pt (getpoint s_pt "\nSelect Line End Point : "))
		(entmakex (list	'(0 . "LINE")
				'(100 . "AcDbEntity")
				'(100 . "AcDbLine")
				(cons 10 s_pt)
				(cons 11 e_pt)
				'(6 . "DASHED")
			  )
		)
	   )
    )
    (alert "Load DASHED linetype please...")
  )
  (princ)
)

🍻

 

0 Likes
Message 11 of 11

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

... I have a small code for insertion of a line: (command "line" "First point" "Second point" "") but I am unsure how to make this code insert a dashed line ....


I agree that it's a good plan to put it on a Layer with a Dashed linetype.  But it's not necessary to load that linetype ahead of time, nor to check whether it's loaded, if you use the (command) function to make the Layer, rather than (entmake).

 

(command

  "_.Layer" "_make" "YourLayerName" "_ltype" "DASHED" "" ""

  "_.line" Firstpoint Secondpoint ""

)

 

That's one of the advantages of the (command) function [in addition to taking less code] -- it will find  linetypes that are in the ACAD.lin file, in a LAYER or CHPROP [or CHANGE with Properties option] command, even when they do not yet exist in the drawing!

 

If you have a good reason to want the linetype to be a property override  on the Line, rather than getting that from its Layer:

 

(command

  "_.line" Firstpoint Secondpoint ""

  "_.chprop" "_last" "" "_ltype" "DASHED" ""

)

 

again, whether or not the linetype is already loaded.

Kent Cooper, AIA