.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get hatch area: Hatch from exploded parcel.

25 REPLIES 25
SOLVED
Reply
Message 1 of 26
ysRBEDG
1470 Views, 25 Replies

Get hatch area: Hatch from exploded parcel.

Hi,

 

I'm am trying to develop a method to assign a color to individual Civil 3D parcels. I don't want to create a seperate parcel style for each color, so my current method is as follows: I create my parcels, assign a solid fill, and then explode the parcels

(I have over 1000 parcels - and the layout will likely change, so hatching them manually will take along time.)

 

I have created a .NET command that will assign the correct color to a hatch based on the area. I have tested it on hatches I create reguarly, and it works fine. The hatches from exploded parcels don't work, however - they don't have any "area" property associated with them.

 

(What is interesting, is this; if I drag the hatch boundry even slightly the properties pallete refreshes and the hatch area is displayed.)

 

If anyone can help with this, it is much appreciated.

 

 

Tags (1)
Labels (2)
25 REPLIES 25
Message 2 of 26
ActivistInvestor
in reply to: ysRBEDG

Have you tried opening each Hatch (for write) and calling it's EvaluateHatch() method?

Message 3 of 26
ysRBEDG
in reply to: ActivistInvestor

yes, doesn't seem to help.
Message 4 of 26
kdub_nz
in reply to: ysRBEDG

@ysRBEDG ,

excuse my ignorance :

 

Are the Hatches unique to  Civil 3D parcels ?

or are they generic AutoCAD API hHatches ??

 

Regards,

 


// Called Kerry in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect.
Sometimes the question is more important than the answer.

class keyThumper<T> : Lazy<T>;      another  Swamper

Message 5 of 26
hosneyalaa
in reply to: ysRBEDG

Can you attached example drawing 

Message 6 of 26
ysRBEDG
in reply to: ysRBEDG

Regarding @kdub_nz 's question about the hatch type - I'm not really sure. I do know though, that when I cast my DatabaseObject to a Hatch it works fine (Hatch h = (Hatch)myDatanaseObject).

 

I have attached a sample drawing as @hosneyalaa requested.

Message 7 of 26
norman.yuan
in reply to: ysRBEDG

Not sure what your ultimate goal is: do you want to permanently draw hatches over each Parcel and set the hatch color based on the area; or these colored hatches are only needed temporarily in a certain CAD process? That is, what is the purpose to create hatches on top of each parcel? You might create different Parcel styles (with different area fill configured) and use code to assign certain styles to the parcels based on their area. 

 

In the case you must draw hatches on top of the parcels for certain reason(s), exploding the parcel would only work if the parcel style's area fill is set to be visible. If the area fill is not visible, the exploded DBObject is a closed polyline, and you need to create the hatch from this polyline. Because of this, I'd not do exploding. Instead, I'll use Parcel.BaseCurve property to obtain a closed polyline and create the hatch. Again, I do not know why you want to place hatches on top of parcels while the parcels can be easily colored/filled with different styles.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 8 of 26
ActivistInvestor
in reply to: ysRBEDG

Can you post a sample .dwg file with some misbehaving hatches? 

Message 9 of 26
ysRBEDG
in reply to: norman.yuan

I will try using Parcel.Basecurve as suggested. Thanks.

 

Regarding you question as to why i am creating hatches and not using parcel styles - I want to color each parcel differently (based on the area - sort of like a heatmap). I would have to create hundreds or thousands of styles to cover all the possible colors.

Message 10 of 26
ysRBEDG
in reply to: ActivistInvestor

I posted a file above.
Message 11 of 26
Jeff_M
in reply to: ysRBEDG

@ysRBEDG Why aren't you getting the area from the Parcel?

Jeff_M, also a frequent Swamper
EESignature
Message 12 of 26
hosneyalaa
in reply to: ysRBEDG

using parcel styles

 

Capture1.JPGCapture2.JPG

Message 13 of 26
ActivistInvestor
in reply to: ysRBEDG

 

The only thing I can tell you is that the Area property is returning eNotApplicable, and that the hatches being created by exploding the parcels appear to have issues.

 

Since the Parcel object is responsible for exploding itself, that's where the problem would most-likely be.

 

Command: (setq e (car (entsel)))
Select object: <Entity name: 2108222e400>

Command: (vlax-dump-object (vlax-ename->vla-object e))
; IAcadHatch: AutoCAD Hatch Interface
; Property values:
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00007ff751d76b48>
;   Area (RO) = AutoCAD.Application: Not applicable
;   AssociativeHatch = 0
;   BackgroundColor = #<VLA-OBJECT IAcadAcCmColor 0000021088fed580>
;   Document (RO) = #<VLA-OBJECT IAcadDocument 0000021882bb5d78>
;   Elevation = 0.0
;   EntityTransparency = "ByLayer"
;   GradientAngle = 0.0
;   GradientCentered = -1
;   GradientColor1 = Exception occurred
;   GradientColor2 = Exception occurred
;   GradientName = ""
;   Handle (RO) = "8CE8"
;   HasExtensionDictionary (RO) = 0
;   HatchObjectType = 0
;   HatchStyle = 0
;   Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 000002103d207998>
;   ISOPenWidth = 100
;   Layer = "0"
;   Linetype = "ByLayer"
;   LinetypeScale = 1.0
;   Lineweight = -1
;   Material = "ByLayer"
;   Normal = (0.0 0.0 1.0)
;   NumberOfLoops (RO) = 1
;   ObjectID (RO) = 42
;   ObjectName (RO) = "AcDbHatch"
;   Origin = (0.0 0.0)
;   OwnerID (RO) = 43
;   PatternAngle = 0.0
;   PatternDouble = 0
;   PatternName (RO) = "SOLID"
;   PatternScale = 1.0
;   PatternSpace = 1.0
;   PatternType (RO) = 1
;   PlotStyleName = "ByLayer"
;   TrueColor = #<VLA-OBJECT IAcadAcCmColor 0000021088fecfe0>
;   Visible = -1
T

 

 

Command: MGDUMP

Dump at offset 69 in file:line:column <filename unknown>:0:0
====[Autodesk.AutoCAD.DatabaseServices.Hatch]====
  Origin = (0,0)
  Area = (NotApplicable)
  NumberOfHatchLines = 0
  HatchStyle = Normal
  NumberOfPatternDefinitions = 0
  PatternDouble = False
  PatternScale = 1
  PatternSpace = 1
  PatternAngle = 0
  PatternName = SOLID
  PatternType = PreDefined
  GradientShift = 0
  ShadeTintValue = 0
  GradientOneColorMode = False
  GradientAngle = 0
  GradientName =
  GradientType = PreDefinedGradient
  IsSolidFill = True
  IsHatch = True
  IsGradient = False
  HatchObjectType = HatchObject
  Associative = False
  NumberOfLoops = 1
  BackgroundColor =
  Normal = (0,0,1)
  Elevation = 0
  EdgeStyleId = (0)
  FaceStyleId = (0)
  VisualStyleId = (0)
  ForceAnnoAllVisible = False
  BlockName = *Model_Space
  MaterialMapper = (null)
  MaterialId = (2269922462912)
  Material = ByLayer
  ReceiveShadows = False
  CastShadows = False
  Hyperlinks = Autodesk.AutoCAD.DatabaseServices.HyperLinkCollection
  CloneMeForDragging = True
  CompoundObjectTransform = (NotApplicable)
  GeometricExtents = ((2410.9670957322232,7218.544592097867,0),(2445.1967031662352,7289.555230898783,0))
  Ecs = ((1,0,0,0),(0,1,0,0),(0,0,1,0),(0,0,0,1))
  IsPlanar = True
  CollisionType = Solid
  LineWeight = ByLayer
  Visible = True
  LinetypeScale = 1
  LinetypeId = (2268938375504)
  Linetype = ByLayer
  LayerId = (2268938375424)
  Layer = 0
  PlotStyleNameId = ((0),PlotStyleNameByLayer)
  PlotStyleName = ByLayer
  Transparency = (0)
  EntityColor = Autodesk.AutoCAD.Colors.EntityColor
  ColorIndex = 256
  Color = BYLAYER
  BlockId = (2268938375664)
  PaperOrientation = False
  Annotative = False
  HasFields = False
  AcadObject = System.__ComObject
  ClassID = dea79e20-55fa-4440-ba44-74e6c5abd579
  ObjectBirthVersion = AC1013,Release0
  HasSaveVersionOverride = False
  IsObjectIdsInFlux = False
  UndoFiler = (null)
  IsAProxy = False
  IsTransactionResident = True
  IsReallyClosing = False
  IsCancelling = False
  IsUndoing = False
  IsNotifying = False
  IsNewObject = False
  IsModifiedGraphics = False
  IsModifiedXData = False
  IsModified = False
  IsNotifyEnabled = False
  IsWriteEnabled = False
  IsReadEnabled = True
  IsErased = False
  IsEraseStatusToggled = False
  XData = (null)
  MergeStyle = Ignore
  ExtensionDictionary = (0)
  Drawable = Autodesk.AutoCAD.DatabaseServices.Hatch
  Database = Autodesk.AutoCAD.DatabaseServices.Database
  Handle = 8CE8
  OwnerId = (2268938375664)
  ObjectId = (2269926056960)
  Id = (2269926056960)
  IsPersistent = True
  DrawStream = (null)
  Bounds = ((2410.9670957322232,7218.544592097867,0),(2445.1967031662352,7289.555230898783,0))
  DrawableType = Geometry
  AutoDelete = False
  IsDisposed = False
  UnmanagedObject = 2270030134112
Command: DWGDUMP

[0] SoftPointerId: (2268938375664)
[1] UInt32: 0
[2] HardOwnershipId: (0)
[3] HardPointerId: (2268938375424)
[4] HardPointerId: (2268938375504)
[5] HardPointerId: (2269922462912)
[6] Byte: 0
[7] Bool: False
[8] Bool: False
[9] Bool: False
[10] Bool: False
[11] Bool: False
[12] UInt16: 256
[13] Real: 1
[14] UInt16: 0
[15] Byte: 29
[16] UInt32: 0
[17] UInt32: 0
[18] Real: 0
[19] Real: 0
[20] UInt32: 0
[21] Real: 0
[22] UInt32: 0
[23] Text:
[24] Real: 0
[25] Vector3d: (0,0,1)
[26] Text: SOLID
[27] Bool: True
[28] Bool: False
[29] Int32: 1
[30] Int32: 2
[31] Bool: False
[32] Bool: True
[33] Int32: 4
[34] Point2d: (2445.1967031662352,7218.544592097867)
[35] Point2d: (2410.9670957322232,7218.544592097867)
[36] Point2d: (2410.9670957322232,7289.555230898783)
[37] Point2d: (2445.1967031662352,7289.555230898783)
[38] Int32: 0
[39] Int16: 0
[40] Int16: 1
[41] Int32: 1
[42] Point2d: (0,0)
[43] Int32: 1
[44] Int32: 0
[45] Text: AcDbPolyline
[46] SoftPointerId: (0)
[47] UInt32: 0
[48] HardOwnershipId: (0)
[49] HardPointerId: (0)
[50] HardPointerId: (0)
[51] HardPointerId: (0)
[52] Byte: 0
[53] Bool: False
[54] Bool: False
[55] Bool: False
[56] Bool: True
[57] Bool: True
[58] HardPointerId: (0)
[59] UInt16: 257
[60] Real: 1
[61] UInt16: 0
[62] Byte: 28
[63] UInt16: 512
[64] UInt32: 4
[65] Point2d: (2445.1967031662352,7218.544592097867)
[66] Point2d: (2410.9670957322232,7218.544592097867)
[67] Point2d: (2410.9670957322232,7289.555230898783)
[68] Point2d: (2445.1967031662352,7289.555230898783)
[69] Bool: True
[70] Bool: True
[71] HardPointerId: (0)
[72] Int32: 2
[73] Text: ACDB_ANNOTATIONSCALES
[74] HardPointerId: (0)
[75] Bool: False
[76] Bool: True
[77] Int32: 0
[78] Int16: 4
[79] Bool: True
[80] Bool: True
[81] HardPointerId: (0)
[82] UInt16: 0
[83] Real: 1
[84] Vector3d: (0,0,0)
[85] Int32: 1
[86] Int32: 2
[87] Bool: True
[88] Text: ACDB_ANNOTATIONSCALE_VIEW_COLLECTION
[89] HardPointerId: (0)
[90] Bool: False
[91] Bool: True
[92] Int32: 0
[93] Int16: 4
[94] Bool: True
[95] Bool: True
[96] HardPointerId: (0)
[97] UInt16: 0
[98] Real: 1
[99] Vector3d: (0,0,0)
[100] Int32: 1
[101] Int32: 2
[102] Bool: True
[103] SoftPointerId: (0)
[104] Vector3d: (0,0,1)
[105] Real: 0
[106] Bool: False
[107] UInt16: 0
Command: DXFDUMP

(-1: (2269926056960))
(0: HATCH)
(330: (2268938375664))
(5: 8CE8)
(100: AcDbEntity)
(67: 0)
(410: Model)
(8: 0)
(100: AcDbHatch)
(10: (0,0,0))
(210: (0,0,1))
(2: SOLID)
(70: 1)
(71: 0)
(91: 1)
(92: 2)
(72: 0)
(73: 1)
(93: 4)
(10: (2445.1967031662352,7218.544592097867,0))
(10: (2410.9670957322232,7218.544592097867,0))
(10: (2410.9670957322232,7289.555230898783,0))
(10: (2445.1967031662352,7289.555230898783,0))
(97: 0)
(75: 0)
(76: 1)
(98: 1)
(10: (0,0,0))
(450: 0)
(451: 0)
(460: 0)
(461: 0)
(452: 0)
(462: 0)
(453: 0)
(470: (null))

 

 

Message 14 of 26
ysRBEDG
in reply to: Jeff_M

I can, but then I wouldn't know which parcel area is associated with which hatch.

I guess I can make a dictionary of the parcel locations and sizes, and then after the parcels are exploded, look up each hatch location to find the associated parcel size.
Message 15 of 26
norman.yuan
in reply to: ysRBEDG

Well, for the sake of sticking with your logic (exploding each Parcel object to get a Hatch and its area, then determine the color of the hatch), I do not see why you need to store the parcel location and its size(area) and match the parcels and hatches later. You can simply loop through the Parcel ObjectIdCollection obtained from Site.GetParcelIds() (pseudo code):

 

 

using (var tran = [start transaction])

{

   var parcelIds=[site].GetParcelIds();

  foreach (ObjectId id in parcelIds)

  {

    var parcel=(Parcel)tran.GetObject(id,....);

    var area=parcel.Area;

    var hatch=ExplodeTheParcel(parcel);

    var colorIndex=DetermineRequiredColor(area);

    // Then you can set the hatch's color 

    // add the hatch to the database/modelspace

  }

  tran.Commit();

}

 

Of course, as I previously said, if the parcel's style is set to not show its fill, then the exploding would not give you a hatch. So, I'd prefer creating the hatch based on the Parcel's BaseCurve instead of exploding. As side benefit, you would not run into the missing "area" issue at all. Or, maybe a different option, you could also try to create MPolygon instead of Hatch?

 

Norman Yuan

Drive CAD With Code

EESignature

Message 16 of 26
Jeff_M
in reply to: norman.yuan

Perhaps I'm not exploding correctly, but the only hatch I get when exploding a Parcel is the background mask for the ParcelAreaLabel. If I use a label set to not display anything, no hatch is in the exploded objects collection. So how, exactly, is a Parcel exploded with the fill hatch? 

I agree with @norman.yuan that the hatch should be created from the BaseCurve of the Parcel.

Jeff_M, also a frequent Swamper
EESignature
Message 17 of 26
norman.yuan
in reply to: ysRBEDG

As the Parcel Style editing dialog shows, if the "Parcel Area Fill" is set to not visible (which is default), then exploding a parcel would not create a Hatch. so, if the OP want to go with the exploding approach, he/she have to make sure the "Parcel Area Fill" is turned on.

normanyuan_0-1724115565273.png

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 18 of 26
Jeff_M
in reply to: norman.yuan

@norman.yuan With the area fill turned on in the style in use, the only hatch I get is the background mask of the label. (Civil 3D 2023) Tried with a Solid fill and a standard hatch pattern.

Jeff_M, also a frequent Swamper
EESignature
Message 19 of 26
norman.yuan
in reply to: ysRBEDG

@Jeff_M 

See attached video clip, showing how exploding parcel could generate different entities, depending on the parcel style. Note, running command "Explode" against Parcel is much like the API call of Blockreference.ExplodeToOwnerSpace(), that is, besides generating element entities, the parcel itself remain unchanged, while the command in plain AutoCAD erases the original entity to be exploded.

Norman Yuan

Drive CAD With Code

EESignature

Message 20 of 26
Jeff_M
in reply to: norman.yuan

@norman.yuan Thanks, and yes, I understand all that. Performing the explode in code does not give me that result. I only add the Hatch object to the drawing and color is green. It is the same as the background mask for the label, there is no hatch for the overall parcel.

2024-08-20_18-48-57.png2024-08-20_18-41-06.png

If you can get the full hatch, what am I doing wrong?

Jeff_M, also a frequent Swamper
EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report