Code Red > .NET

Geometric Constraints

(1/2) > >>

nekitip:
I was trying to do a simple thing: insert text or block fixed to the midpoint of curve, horizontal or coplanar. That is possible in AutoCAD without problem, but how to do it programatically?
The only thing "close" to it in entire two hours of googleing was an old post here, written by Jeff H https://www.theswamp.org/index.php?topic=38418.0 I've couldn't find anything else unless it's objarx something...
I've really tried to understand what it does, but I got lost in entire concep...
Any help?

EDIT:
also, running code from that post is not going without problems - cad complaines that "one or more objects in this drawing cannot be saved to the specified format...", both on autosave and on save

nekitip:
It took me a while to dig this out, but gold is found is here!
https://forums.autodesk.com/autodesk/attachments/autodesk/152/24647/1/Parametric%20VB%20Net%20Code.txt

Plenty of golden code that does compile without error. However, I still have no idea how to align text to curve and just guessing and trying blindely at the moment...

Atook:
Try something like this for your text rotation:

--- Code - C#: ---// rotationVector3d deriv = Pipe.Polyline.GetFirstDerivative(insParam);rotation = deriv.RadsFromXAxis(); /// <summary>/// Returns the angle in rads from the x-axis that is used for the rotation of a block aligned with the vector/// </summary>/// <param name="vec"></param>/// <returns></returns>public static double RadsFromXAxis(this Vector3d vec){  Vector3d xAxis = new Vector3d(1, 0, 0);  return Math.Atan2(vec.Y - xAxis.Y, vec.X - xAxis.X);} 
The RadsFromXAxis is a polyline extension found in Gile's GeometryExtensions. I can't find the download right now, but I'm pretty sure I picked it up here at the swamp.

Search for those and find them, some real gems from learning there.

nekitip:
I'm glad you're interested. However, I'm not sure if manual rotations are what I'm after.
The thing I'm talking about is a way to make CAD automaticaly align and rotate entites based on a rules you define.
This is really powefull tool, however, this link I provided (and refered to as gold) is the only other (beside Jeffs) available online!

There is also another link to blog of how to apply blocks to each polyline vertice, but I'm unable to find it. I literally opened hundreds of pages this weekend, trying to find something, so It's kind of lost in browser history.

Also, not directly related, but interesting:
http://adndevblog.typepad.com/autocad/2012/03/working-with-associative-parameters-from-api.html

The link I provided is a complete enough, however, I have no idea of what goes where. For example, line has edges - what text has? How to find point of interest for text?...

I think Jeff H could help maybe...

nekitip:
finally, five frustrating hours later and more then 50 trial and error attempts, some success!
so, the most important thing is: whereas a line has edge; dbpoint, text and block have vertex! Once you realise that, it's 100 times easier, and you'll be able to spot patterns in code

then, you should only safely use this sub:

--- Code - vb.net: ---Public Sub SetEntCoincidentConstraint(ByVal curve1 As Curve, ByVal ent1 As Entity, ByVal curveEnd1 As CurvePoint, ByVal entType As SubentityType, ByVal trans As Transaction)            Using trans2 As Transaction = trans.TransactionManager.StartTransaction 'work with sub transactions in order to allow 1 undo that undoes it all.                Dim SubEntEdgePath1 As FullSubentityPath 'logical path to the edge (one edge object pretty simple)                Dim SubEntEdgePath2 As FullSubentityPath                Dim subEntPointPath1 As FullSubentityPath 'logical path to the user selected point (usually start, end, or mid)                Dim subEntPointPath2 As FullSubentityPath                'create a logical path from the object to its sub entities                CreateSubEntityPath(curve1, curveEnd1, SubEntEdgePath1, subEntPointPath1, trans2)                SubEntEdgePath2 = CreateSubEntityPath(ent1, entType)   'cutting point                subEntPointPath2 = CreateSubEntityPath(ent1, entType)  'point where                 'get the constraint group that exists on the same plane as our points (in this case just wcs + elevation, but if you get more advanced, this may need to be modified big time)                Dim consGrpId As ObjectId = GetConstraintGroup(True, trans2)                'use the logical paths to create a constraint between 2 selected points(CurvePoint) of the 2 supplied edges(curves)                Dim consGeomEdge1 As ConstrainedGeometry = Nothing                Dim consGeomEdge2 As ConstrainedGeometry = Nothing                Using constGrp As Assoc2dConstraintGroup = DirectCast(trans2.GetObject(consGrpId, OpenMode.ForWrite, False), Assoc2dConstraintGroup)                    Try                        consGeomEdge1 = AddConstrainedGeometry(constGrp, SubEntEdgePath1)                    Catch ex As Exception                        'aready there move on                    End Try                    Try                        consGeomEdge2 = AddConstrainedGeometry(constGrp, SubEntEdgePath2)                    Catch ex As Exception                        'aready there move on                    End Try                    Dim paths As FullSubentityPath() = {subEntPointPath1, subEntPointPath2}                    Dim newConstraint As GeometricalConstraint = constGrp.AddGeometricalConstraint(GeometricalConstraint.ConstraintType.Coincident, paths)                End Using                trans2.Commit()            End Using        End Subyou will be able to add block or text to stick to midpoint of curve
So now it is possible to do some of the things, but I'm still unable to actually align text or block... how to do that?

Navigation

[0] Message Index

[#] Next page

Go to full version