Reference Geometry: Coordinate System creation

I'm trying to create a macro that retrieves persistent reference IDs from a .txt file (created from another macro). This .txt file has stored 64-bit values for: Sketch Point ID (comma) Sketch Line ID

I then use these objects and (per line) create a coordinate system to align to these objects.

While Not oFile.AtEndOfStream<br><br> Line = oFile.ReadLine<br> ent = Split(Line, ",")<br><br> ' Retrieve sketch point ID and set object.<br> skPointID = Base64ToArray(ent(0))<br> Set skPoint = swModel.Extension.GetObjectByPersistReference3(skPointID, err)<br><br> ' Retrieve sketch line ID and set object.<br> skLineID = Base64ToArray(ent(1))<br> Set skLine = swModel.Extension.GetObjectByPersistReference3(skLineID, err)<br><br> ' Create coordinate system and get definition.<br> Set swFeat = swFeatMgr.InsertCoordinateSystem(False, False, False)<br> Set cSysData = swFeat.GetDefinition<br><br> ' Find CS name and send feature to end of feature tree.<br> ftname = swFeat.Name<br> bRet = swModel.Extension.ReorderFeature(ftname, ftname, swMoveToEnd)<br><br> cSysData.AccessSelections swModel, swComp<br> cSysData.OriginEntity = skPoint<br> cSysData.XAxisEntities = skLine<br><br> boolstatus = swFeat.ModifyDefinition(cSysData, swModel, Nothing)<br> cSysData.ReleaseSelectionAccess<br><br> Wend<br><span class="line-numbers-rows"><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span></span>

The above code is a snippet of what I currently have running; however, it has only been able to assign cSysData.OriginEntity [line 23] to 'skPoint'. I cannot seem to get the designation of cSysData.XAxisEntities to 'skLine'. Does anyone see an issue with my order of operations here? I have made skPoint & skLine Object type variables, and am worried that I cannot assign skLine object to xAxisEntities.

Thanks in advance,

Austin

SolidworksApi/macros
Answers 2
AT
AT 2021-04-08 Best Answer

XAxisEntities expects an array, not a single element. You also need to use the array of specific types (i.e. ISketchLine()) instead of Object() or use the DispatchWrapper() array. You also do not need to call ReleaseSelectionAccess after you called ModifyDefinition, the later one would release feature automatically.

Alternatively you can preselect the entities with the valid marks to create a CS on a fly instead of modifying its definition afterwards.

AS
AS 2021-04-08

Artem - you're a life saver. I try to do my research before posting questions, but your answers make things look so simple.

Your answer to my question is correct so I will mark it as such. I ultimately didn't need any of it as I incorporated your suggestion - preselection of the sketch point and sketch line...I don't know why I hadn't thought of that, but the improvement to performance is tenfold. This was my first time thinking about marking sketch entities like this, so thanks for the suggestion. Little things like that really helps develop my thinking about these macros and improves my approach to each task. I had already stored the IDs and planned on gathering the info from the text file, just didn't click that I could use this information with SelectionMgr::SelectData.

Austin