CorelDraw X21 SetPosition on a DXF import macro is not compatible with X6-X19 versions.
Working X19 script code that gives the "Run-time error '91' Object variable or with block variable not set" in X21
Version X19 origin is 0,0 bottom left by default without any other settings.
Would like correct X21 SETPOSITION code.
The ActiveDocument.ReferencePoint = cdrBottomLeft does not seem to help.
Thank you in Advance
ActivePage.GuidesLayer.Editable = False ActivePage.GuidesLayer.Editable = True Dim impopt As StructImportOptions Set impopt = CreateStructImportOptions impopt.MaintainLayers = True Dim impflt As ImportFilter ' Set the path for Drill time DXF file Set impflt = ActivePage.Layers("DT").ImportEx("C:\wellsite\d6unit\zDT.DXF", cdrDXF, impopt) With impflt .Projection = 0 ' FilterDXFLib.dxfTop .AutoReduceNodes = False .Scaling = 1 ' FilterDXFLib.dxfEnglish .Finish End With Dim s1 As Shape Set s1 = ActiveShape ' ****************************** Track1 ' Set begining of Drill Time Curve 5" per 100 ft s1.SetPosition 0.241, 55.681 ' Run-time error '91' Object variable or with block variable not set ' ******************************
Please, edit your question and replace the pictures with your code. You can be better helped if we are able to make some tests with the involved code...
On which code line does the error appear? And which error, if any? What does "not work" mean?
I think, that ImportEx operation was not successfull. And nothing selected. s1 points to null shape and s1.SetPosition gives run-time error
Similar macro used daily for years that imports a DXF polyline. Works in both Corel x6 & 2019. Gives
the " Run-time error '91' Object variable or with block variable not set" in 2021
Stops at S1.SetPosition 0.241, 55.681 . The DXF will import manually in 2021
An idea on a new syntax would be great.
Sub XLasSP() ' Recorded 3/26/2014 ActivePage.GuidesLayer.Editable = False ActivePage.GuidesLayer.Editable = True Dim impopt As StructImportOptions ' BEGIN OF TOP LINE Set impopt = CreateStructImportOptions impopt.MaintainLayers = True Dim impflt As ImportFilter Set impflt = ActivePage.GuidesLayer.ImportEx("C:\wellsite\d6unit\lasSP.DXF", cdrDXF, impopt) With impflt .Projection = 0 ' FilterDXFLib.dxfTop .AutoReduceNodes = False .Scaling = 1 ' FilterDXFLib.dxfEnglish .Finish End With Dim s1 As Shape Set s1 = ActiveShape ' x left edge report 0.241 ' y begin line @ 55.681
' ***************************** Track1 ' Set begining of SP curve s1.SetPosition 0.241, 55.681 ' ****************************** Dim grp1 As ShapeRange Set grp1 = s1.UngroupExgrp1.SetOutlineProperties 0.014, OutlineStyles(8), CreateCMYKColor(100, 0, 100, 0), LineCaps:=cdrOutlineSquareLineCaps, DashDotLength:=0# ' END OF TOP LINE End Sub
I made some tests and observed that it is not possible (using the above code) to import the file directly on the "Guides" layer, even if the code requires it. Corel creates a new layer (naming it "0") and place the object on this one.
In order to bypass this behavior, please try replacing of 'Set s1 = ActiveShape' with `Set s1 = ActiveLayer.Shapes.Last`. It will set the (last) shape on the newly (active) created layer and the rest of the code should work as you need.
Solved: In earlier version x6-2019 I recorded the scripts 6 years ago and got lucky. Corel picked up the layer name on import. In 2021 you need to create the layer first thing. Then import the DXF, at a specific SetPosition X, Y (0,0 btm left) Depending on the version of DXF, poly lines are generally under 100 segments and segments are joined. In my case the poly lines are near 120" . The last code lines group the segments, and thus dash lines can set and unbroken top to bottom. Yes, Set s1 = ActiveLayer.Shapes.Last works.
Creating the layer before the import is the solution for ver 2021. 2021 no longer picks up the layer name in the DXF on import. Thank you
Sub xSPcreate() ' Recorded 12/8/2021 Dim lr1 As Layer Set lr1 = ActivePage.CreateLayer("SP") lr1.Name = "SP" Dim impopt As StructImportOptions Set impopt = CreateStructImportOptions With impopt.ColorConversionOptions .SourceColorProfileList = "sRGB IEC61966-2.1,U.S. Web Coated (SWOP) v2,Dot Gain 20%" .TargetColorProfileList = "sRGB IEC61966-2.1,U.S. Web Coated (SWOP) v2,Dot Gain 20%" End With Dim impflt As ImportFilter Set impflt = lr1.ImportEx("C:\wellsite\d6unit\lasSP.DXF", cdrDXF, impopt) With impflt .Projection = 0 ' FilterDXFLib.dxfTop .AutoReduceNodes = False .Scaling = 1 ' FilterDXFLib.dxfEnglish .Finish End With Dim s1 As Shape Set s1 = ActiveShape s1.SetPosition 0.241, 69.681 Dim grp1 As ShapeRange Set grp1 = s1.UngroupEx grp1.SetOutlineProperties 0.013, Color:=CreateRGBColor(0, 0, 255) grp1.SetOutlineProperties 0.014, OutlineStyles(8), CreateCMYKColor(100, 0, 100, 0), LineCaps:=cdrOutlineSquareLineCaps, DashDotLength:=0#End Sub