Create Rectangle with Hatch

Create Rectangle with Hatch

Anonymous
Not applicable
868 Views
13 Replies
Message 1 of 14

Create Rectangle with Hatch

Anonymous
Not applicable

Kindly, I need to draw a rectangle with hatch on a specific layer with color by layer and​ the hatch is ansi31 angle 0 size 500 and on another specific layer with color by layer

thx

0 Likes
869 Views
13 Replies
Replies (13)
Message 2 of 14

Jonathan3891
Advisor
Advisor

See if this will work for you.

 

(defun c:ttt (/ olayer Pnt1 Pnt2 Ent Obj)
  (setq olayer (getvar 'clayer)
	Pnt1 (getpoint "\nSpecify first corner")
	Pnt2 (getpoint "\nSpecify second corner")
	Ent (entlast)
	)
  (command "_layer" "m" "Rectangle" "c" "6" "" "lt" "continuous" "" "")
  (command "_rectangle" Pnt1 Pnt2)
  (command "_layer" "m" "Hatch" "c" "254" "" "lt" "continuous" "" "")
  (if (/= Ent (setq Obj (entlast)))
    (command "_.-hatch" "S" Obj "" "P" "ansi31" "1" "0" "");1 = Scale, 0 = Angle
    )
  (setvar 'clayer olayer)
  (princ)
  )

Jonathan Norton
Blog | Linkedin
0 Likes
Message 3 of 14

yanndellamaggiora
Contributor
Contributor

THANKS BUT NO RECTANGLE VISIBILITY AT TIME

0 Likes
Message 4 of 14

pendean
Community Legend
Community Legend

@yanndellamaggiora Can you elaborate please?

0 Likes
Message 5 of 14

ВeekeeCZ
Consultant
Consultant

Just replace the second getpoint with getcorner, that's all you need.

0 Likes
Message 6 of 14

yanndellamaggiora
Contributor
Contributor

Thank you for your quick reply.
However, I'm afraid I didn't understand correctly.
I changed "getpoint" to "getcorner," but it doesn't seem to be working. I'm a beginner.
Could you write it down for me, please?

0 Likes
Message 7 of 14

yanndellamaggiora
Contributor
Contributor

Pendant le premier et le deuxième point, je ne vois pas le rectangle en temps réel ;
il n’apparaît qu’à la fin ;
donc je ne sais pas exactement où je positionne mon rectangle.

0 Likes
Message 8 of 14

Kent1Cooper
Consultant
Consultant

The (getcorner) function needs a reference point:

....

    Pnt2 (getcorner Pnt1 "\nSpecify second corner")

....

Kent Cooper, AIA
0 Likes
Message 9 of 14

Sea-Haven
Mentor
Mentor

Why not also this as rectang is last object.

 

(command "_.-hatch" "S" Obj "" "P" "ansi31" "1" "0" "");1 = Scale, 0 = Angle

(command "_.-hatch" "S" (entlast) "" "P" "ansi31" "1" "0" "");1 = Scale, 0 = Angle
0 Likes
Message 10 of 14

yanndellamaggiora
Contributor
Contributor

Hello,
Thanks, it works, you're great.
I was wondering if we could choose to make a polygon into a polyline or a rectangle?
What do you think?

0 Likes
Message 11 of 14

yanndellamaggiora
Contributor
Contributor

It would also be interesting to have the options of the standard rectangle command (dimension, rotation, etc.)

0 Likes
Message 12 of 14

Kent1Cooper
Consultant
Consultant

@yanndellamaggiora wrote:

It would also be interesting to have the options of the standard rectangle command (dimension, rotation, etc.)


You can have all the options in that command by using (command-s) to run it, and it will keep taking input until the command is completed.  Taking parts from various other messages and incorporating that:

(defun c:RH (/ olay); = Rectangle with Hatch
  (setq olay (getvar 'clayer))
  (command "_.layer" "m" "Rectangle" "c" "6" "" "")
  (command-s "_.rectang")
  (command
    "_.layer" "_make" "Hatch" "_color" 254 "" ""
    "_.-hatch" "_select" (entlast) "" "_properties" "ANSI31" "1" "0" ""
  )
  (setvar 'clayer olay)
  (prin1)
)

There's no need for variables for the corners, and you can see it forming as you move the cursor after giving it a first corner -- no (getpoint) or (getcorner) functions are needed, because the command's own prompts cover it all.

Also, there's no need to assign Continuous as a linetype to a new Layer -- that is the default.  Only if the Layer might already exist but with the "wrong" linetype would you need to assign that.

[A nit-picky item:  The real command name is RECTANGRECTANGLE works, but is only an alias.]

 

Kent Cooper, AIA
0 Likes
Message 13 of 14

Kent1Cooper
Consultant
Consultant

@yanndellamaggiora wrote:

.....
I was wondering if we could choose to make a polygon into a polyline or a rectangle?
....


Can you explain in greater detail?  Both the POLYGON and RECTANG commands result in Polyline objects.  You can't make a polygon into a Polyline, because it already is one.  And you can't make a polygon into a rectangle if it isn't already one, except by moving vertices around, which seems beyond the scope of this Topic.  There is no such thing as a Polygon or a Rectangle as an entity type.

If you mean you want to have a choice to make either a polygon or a rectangle or a Polyline [that is not either a regular polygon or a rectangle], such a choice could be built into a routine as an option.  It would need to include the step of specifying the object type you want to draw and Hatch.  And then it may as well also offer Circle and Spline and Ellipse.  [And if you choose Polyline or Spline or Ellipse, the routine would then need to check that what you made is closed before Hatching it in.]  Is something like that what you're wondering about?

Kent Cooper, AIA
0 Likes
Message 14 of 14

yanndellamaggiora
Contributor
Contributor

Thanks its great

0 Likes