Author Topic: Geometric Constraints  (Read 483 times)

0 Members and 1 Guest are viewing this topic.

nekitip

• Mosquito
• Posts: 14
Geometric Constraints
« on: March 24, 2017, 01:04:25 pm »
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
« Last Edit: March 24, 2017, 02:47:16 pm by nekitip »

nekitip

• Mosquito
• Posts: 14
Re: Geometric Constraints
« Reply #1 on: March 26, 2017, 04:05:41 pm »
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

• Swamp Rat
• Posts: 845
Re: Geometric Constraints
« Reply #2 on: March 26, 2017, 06:29:03 pm »
Try something like this for your text rotation:
Code - C#: [Select]
`// 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.
« Last Edit: March 27, 2017, 11:39:22 am by Atook »

nekitip

• Mosquito
• Posts: 14
Re: Geometric Constraints
« Reply #3 on: March 27, 2017, 03:10:00 am »
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:

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

• Mosquito
• Posts: 14
Re: Geometric Constraints
« Reply #4 on: March 27, 2017, 09:42:14 am »
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: [Select]
`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 Sub`
you 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?

Jeff H

• Needs a day job
• Posts: 5863
Re: Geometric Constraints
« Reply #5 on: March 29, 2017, 03:14:58 pm »
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: