Author Topic: entmake & ltype (There is a problem?)  (Read 7854 times)

0 Members and 1 Guest are viewing this topic.

Q1241274614

  • Guest
entmake & ltype (There is a problem?)
« on: February 17, 2013, 09:51:58 AM »
(defun c:ttt()
   (entmakex
     (list
      (cons 0   "LTYPE")
           (cons 100   "AcDbSymbolTableRecord")
           (cons 100   "AcDbLinetypeTableRecord")
           (cons 2   "GAS")
           (cons 3   "---- GAS ---- GAS ---- GAS ---- GAS ---- GAS ----")
           (cons 70   0)
           (cons 72   65)
           (cons 73   3)
           (cons 40   1.27)
           (cons 49   1.0)
           (cons 74   0)
           (cons 49   -0.12)
           (cons 74   2)
           (cons 75   0)
           (cons 46   0.08)
           (cons 50   0.0)
           (cons 44   -0.06)
           (cons 45   -0.04)
           (cons 9   "GAS")
           (cons 49   -0.15)
           (cons 74   0)
          )
)
  )

togores

  • Guest
Re: entmake & ltype (There is a problem?)
« Reply #1 on: February 17, 2013, 10:18:30 AM »
I quote from my book "AutoCAD expert's Visual LISP" (Chapter 10, pages 196-197):
Quote
Programming a Linetype.
Just as we proposed regarding blocks, an application can use its own Linetypes contained in its code, without using any external resource file. The function in Listing 10.38 receives a name and a description, both as strings, and a list of parameters with the values ​​that make up a Linetype definition similar to those included in .LIN files.
Each Linetype occupies two lines of a .LIN file. For example, the CENTER Linetype in the acadiso.lin file found in our system is defined this way:
*CENTER,Center ____ _ ____ _ ____ _ ____ _ ____ _ ____
A, 31.75, -6.35, 6.35, -6.35

In each of these definitions the first line, beginning with an asterisk, contains the name of the Linetype (the asterisk is not part of the name, but an indication that the definition begins there) and after the comma that linetype’s description. This is optional and can include text describing the type of line, a schematic representation of its pattern (using ASCII characters), and a comment.  The next line contains the values ​​that define it geometrically. The letter "A" (meaning Alignment) always appears followed by a series of numbers in which positive values indicate the length of dashes and negative values the length of spaces. Up to 12 dash-length specifications per Linetype are admitted, provided they do not exceed 80 characters in the .LIN file. Only one complete repetition of the Linetype pattern should be included. The first dash-length must be greater than or equal to 0 (visible segment).
The Linetypes can include text characters or shapes that are stored in shape files (SHX). For this purpose special descriptors are used, inserted among the normal dash-length descriptors. Both text and shape descriptors use a very similar format. For the text descriptor:
["text",textstylename,scale,rotation,Xoffset,Yoffset]
And for shapes:
[shapename,shxfilename,scale,rotation,Xoffset,Yoffset]
If a TextStyle is not specified, AutoCAD uses the current one. The scale is specified as s=value, which is multiplied by the text height defined in the text style or internally in the shape. If the text style height or the scale defined in the shape has zero value, scale is used as the Linetype’s text or shape height. The rotation parameter determines the text or shape orientation. It may be specified using the codes "U" (upright) which prevents that text or shapes are displayed upside down, "R" for a rotation relative to the direction of the line and "A" for an absolute rotation relative to the coordinate axes. Specifying "U=0.0" guarantees text or shapes will never appear upside down. Xoffset and Yoffset adjust the spacing between the text or the shape and the distance between the text and the previous pen-up or pen-down stroke in the directions X and Y relative to the direction of the line.
As we can see, this line starts with a dash length of 31.75 units which is followed by a space of 6.35, a short dash of the same size as the space and then another space of the same length as the previous one. This sequence is repeated along the line. As simple as that. The parameters line to be passed to our ent-linetype function (See Listing 10.42) contains these values, but as a list, replacing the commas with spaces. The following expression creates a Linetype name LINE_1 reproducing the geometry of the CENTER line:
(ent-Linetype
    "LINE_1" "Created by entmake" '("A" 31.75 -6.35 6.35 -6.35))

This function is only intended for creating Linetypes made up of dashes and spaces. Creating complex Linetypes, i.e., that include text or shapes, is more complicated as it involves data as the text style or shape definitions that must exist or be loaded previously.
The solution to this dilemma is also possible via entmake designing a function to create text styles with the desired characteristics that can be invoked before defining the complex Linetype. The procedure would be similar: first obtain an entity list of this type of object to use as a prototype using
(entget (tblobjname table-name object-name))
to study the values ​​associated with each group code in the DXF reference. Based on this information a function can be written to build the association list that will be passed to entmake.
(defun ent-Linetype  (name description param-list)
  (entmake
    (append
      (list '(0 . "LTYPE")
            '(100 . "AcDbSymbolTableRecord")
            '(100 . "AcDbLinetypeTableRecord")
            (cons 2 name)
            '(70 . 0)
            (cons 3 description)
            (cons 72 (ascii (nth 0 param-list)))
            (cons 73 (- (length param-list) 1))
            (cons 40 (apply '+ (mapcar 'abs (cdr param-list)))))
      (apply 'append
             (mapcar '(lambda (x) (list (cons 49 x) '(74 . 0)))
                     (cdr param-list))))))

Listing 10.42. Function that creates a new Linetype in the drawing.

Another solution is proposed in page 200, this time more directly related to your question:

Quote
One possible way to load a custom Linetype without having installed custom resource files in our system would consist in writing its definition to a temporary file which would be used to load it. Once a Linetype is loaded in the drawing the external file is no longer necessary, so it can be deleted. To create a temporary text file we can use the vl-filename-mktemp function described in Chapter 8. The function from Listing 10.45 is used to create a custom Linetype evaluating the following expression:
_$ (ax-define-load-ltype "PERS" "Custom line"
  "A,12.7,-5.08,[\"PERS\",STANDARD,S=2.54,U=0.0,X=-2.54,Y=-1.27],-8.35")
nil
_$

Note that to include the double quote character in the definition argument string the control sequence \" should be used , since otherwise they would have been taken as a string delimiter.
(defun ax-define-load-ltype
       (name description definition / file file-id)
  (setq file    (vl-filename-mktemp nil nil ".lin")
        file-id (open file "w"))
  (write-line (strcat "*" name "," description) file-id)
  (write-line definition file-id)
  (close file-id)
  (vla-load (vla-get-Linetypes *aevl:drawing*) name file))

Listing 10.45. Defining and loading a Linetype with ActiveX.
More information can be found in my blog: http://lispexpert.blogspot.com/

Q1241274614

  • Guest
Re: entmake & ltype (There is a problem?)
« Reply #2 on: February 17, 2013, 09:31:48 PM »
I want to know why I wrote a problem, the problem in the!Thank you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Q1241274614

  • Guest
Re: entmake & ltype (There is a problem?)
« Reply #4 on: February 18, 2013, 04:38:35 AM »
Can you help me to change what I wrote above program, have a look there is wrong.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: entmake & ltype (There is a problem?)
« Reply #5 on: February 18, 2013, 07:19:26 AM »
You need to add a reference to a text style:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:ttt()
  2.     (list
  3.       (cons 0   "LTYPE")
  4.       (cons 100   "AcDbSymbolTableRecord")
  5.       (cons 100   "AcDbLinetypeTableRecord")
  6.       (cons 2   "GAS")
  7.       (cons 3   "---- GAS ---- GAS ---- GAS ---- GAS ---- GAS ----")
  8.       (cons 70   0)
  9.       (cons 72   65)
  10.       (cons 73   3)
  11.       (cons 40   1.27)
  12.       (cons 49   1.0)
  13.       (cons 74   0)
  14.       (cons 49   -0.12)
  15.       (cons 74   2)
  16.       (cons 75   0)
  17.       (cons 340 (tblobjname "style" (getvar 'textstyle))) ; Reference a text style.
  18.       (cons 46   0.08)
  19.       (cons 50   0.0)
  20.       (cons 44   -0.06)
  21.       (cons 45   -0.04)
  22.       (cons 9   "GAS")
  23.       (cons 49   -0.15)
  24.       (cons 74   0)
  25.     )
  26.   )
  27. )

togores

  • Guest
Re: entmake & ltype (There is a problem?)
« Reply #6 on: February 18, 2013, 07:34:06 AM »
Entmaking linetypes that include text or shapes seems to be extremely difficult as other threads show: http://www.theswamp.org/index.php?topic=33001.0
But if you read my previous post, I propose a workaround using activex methods. Here is the code:
Code: [Select]
(defun ax-define-load-ltype
       (name description definition / file file-id)
  (setq file    (vl-filename-mktemp nil nil ".lin")
        file-id (open file "w"))
  (write-line (strcat "*" name "," description) file-id)
  (write-line definition file-id)
  (close file-id)
  (vla-load (vla-get-Linetypes *aevl:drawing*) name file)
  (vl-file-delete file))
where *aevl:drawing* is a global pointing to the drawing object like with (setq *aevl:drawing* (vla-get-ActiveDocument (vlax-get-acad-object)))
To create a complex linetype with text you can evaluate:
Code: [Select]
(ax-define-load-ltype "PERS" "Custom line"
  "A,12.7,-5.08,[\"PERS\",STANDARD,S=2.54,U=0.0,X=-2.54,Y=-1.27],-8.35")
This works for me.
« Last Edit: February 24, 2013, 06:08:10 AM by togores »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: entmake & ltype (There is a problem?)
« Reply #7 on: February 18, 2013, 08:36:52 AM »
Nice solution.  8-)
Here is another   http://www.theswamp.org/index.php?topic=21339.msg258481#msg258481

I read in my 2006 documentation that you can not create a linetype.
Perhaps this has changed for newer ACAD versions, but not that I have seen.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: entmake & ltype (There is a problem?)
« Reply #8 on: February 18, 2013, 08:47:21 AM »
... I should have mentioned that I use BricsCAD.
The code in my previous post works just fine in BricsCAD.

1+ for BricsCAD. :-D

Q1241274614

  • Guest
Re: entmake & ltype (There is a problem?)
« Reply #9 on: February 18, 2013, 09:11:09 AM »
not command

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: entmake & ltype (There is a problem?)
« Reply #10 on: February 18, 2013, 11:07:20 AM »
FWIW this also works in BricsCAD:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:ttt_2 ( / lineTypeObject)
  2.   (setq lineTypeObject
  3.     (vla-add
  4.       "GAS"
  5.     )
  6.   )
  7.   (vla-put-description lineTypeObject "---- GAS ---- GAS ---- GAS ---- GAS ---- GAS ----")
  8.   (vlax-put lineTypeObject 'numdashes 3)        ; vla-put-numdashes etc. are not available. Have to use (vlax-put).
  9.   (vlax-put lineTypeObject 'patternlength 1.27)
  10.   (vlax-put lineTypeObject 'dashlengthat 0 1.0)
  11.   (vlax-put lineTypeObject 'dashlengthat 1 -0.12)
  12.   (vlax-put lineTypeObject 'dashlengthat 2 -0.15)
  13.   (vlax-put lineTypeObject 'shapeoffsetat 1 '(-0.06 -0.04))
  14.   (vlax-put lineTypeObject 'shaperotationat 1 0.0)
  15.   (vlax-put lineTypeObject 'shapescaleat 1 0.08)
  16.   (vlax-put lineTypeObject 'textat 1 "GAS")
  17. )

togores

  • Guest
Re: entmake & ltype (There is a problem?)
« Reply #11 on: February 18, 2013, 03:05:53 PM »
Nice! I haven't used Bricscad, but it seems AutoCAD has things to learn from it.
By the way, non-com properties include NumDashes and PatternLength, but not the rest of those exposed by Bricscad.
Those properties can be read and set with getpropertyvalue and setpropertyvalue, but not thr rest.

Q1241274614

  • Guest
Re: entmake & ltype (There is a problem?)
« Reply #12 on: February 20, 2013, 07:19:19 AM »
(defun c:ttt()  (entmakex    (list      (cons 0   "LTYPE")      (cons 100   "AcDbSymbolTableRecord")      (cons 100   "AcDbLinetypeTableRecord")      (cons 2   "GAS")      (cons 3   "---- GAS ---- GAS ---- GAS ---- GAS ---- GAS ----")      (cons 70   0)      (cons 72   65)      (cons 73   3)      (cons 40   1.27)      (cons 49   1.0)      (cons 74   0)      (cons 49   -0.12)      (cons 74   2)      (cons 75   0)      (cons 340 (tblobjname "style" (getvar 'textstyle))) ; Reference a text style.      (cons 46   0.08)      (cons 50   0.0)      (cons 44   -0.06)      (cons 45   -0.04)      (cons 9   "GAS")      (cons 49   -0.15)      (cons 74   0)    )  ))


 not!

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: entmake & ltype (There is a problem?)
« Reply #13 on: February 20, 2013, 07:48:11 AM »
@ Q1241274614:
Apparently my code samples *only* work in BricsCAD. If you use AutoCAD you have to use one of the workarounds that have been posted/linked to in this thread.

Q1241274614

  • Guest
Re: entmake & ltype (There is a problem?)
« Reply #14 on: February 20, 2013, 08:09:04 PM »
Don't work in BricsCAD, can be realized!

MeasureUp

  • Bull Frog
  • Posts: 462
Re: entmake & ltype (There is a problem?)
« Reply #15 on: February 20, 2013, 09:39:30 PM »
Don't work in BricsCAD, can be realized!
你试过上面第7帖的链接吗?
那里的程序是可用于AutoCAD的,你修改一下就行。
Have you tried the link provided by CAB in the post 7 above?
The code on the link page should work for you.
You may have to modify to suit.

Q1241274614

  • Guest
Re: entmake & ltype (There is a problem?)
« Reply #16 on: February 20, 2013, 10:38:24 PM »
not command,use enymake!
只想看看能不能用entmake实现,不用command!

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: entmake & ltype (There is a problem?)
« Reply #17 on: February 21, 2013, 03:33:40 AM »
Don't work in BricsCAD, can be realized!
Not sure what you mean. Before posting my code samples I have tested them on BricsCAD V13.1.12. And they work.