iOS Question B4X XUI ASDraw

marconotsopolo

Member
Licensed User

I am testing this library in an app for my daughter, it is fantastic by the way.. I am using asdraw.exportdrawing and I can see the list contents when iterating through it, would it be feasible to write the contents to a separate file (of an image created), then at a later stage import the file (list) contents using asdraw.importdrawing for editing?. I have tried but am running into an error.

Dim newList As List : newList.initialize
newList = File.ReadList(Dir,testFile)
ASDraw1.ImportDrawing(newList,True)
Error: -[__NSCFString Get:]: unrecognized selector sent to instance 0x30093ca80

Any suggestions would be greatly received.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Tip:

Not good:
B4X:
Dim newList As List : newList.initialize
newList = File.ReadList(Dir,testFile)

Good:
B4X:
Dim newList As List = File.ReadList(Dir, textFile)

About the actual error - please post the full error message. The list returned from File.ReadList will hold string items. Maybe a different type is expected.
 
Upvote 0

marconotsopolo

Member
Licensed User
Noted
B4X:
Dim newList As List = File.ReadList(Dir, textFile)

The generated error
B4X:
Error occurred on line: 285 (ASDraw)
-[__NSCFString Get:]: unrecognized selector sent to instance 0x3010d71c0
Stack Trace: (
  CoreFoundation       ED1BC017-D925-394E-B6D5-FA291931A668 + 540460
  libobjc.A.dylib      objc_exception_throw + 60
  CoreFoundation       ED1BC017-D925-394E-B6D5-FA291931A668 + 1627264
  CoreFoundation       ED1BC017-D925-394E-B6D5-FA291931A668 + 135092
  CoreFoundation       _CF_forwarding_prep_0 + 96
  tNotes               -[b4i_asdraw _importdrawing:::] + 1300
  CoreFoundation       ED1BC017-D925-394E-B6D5-FA291931A668 + 133140
  CoreFoundation       ED1BC017-D925-394E-B6D5-FA291931A668 + 129120
  tNotes               +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1348
  tNotes               -[B4IShell runMethod:] + 320
 tNotes               -[B4IShell raiseEventImpl:method:args::] + 928
 tNotes               -[B4IShellBI raiseEvent:event:params:] + 1008
 tNotes               __33-[B4I raiseUIEvent:event:params:]_block_invoke + 52
 libdispatch.dylib    188FA8F6-305B-3B93-8215-8918C2CC45AF + 8508
 libdispatch.dylib    188FA8F6-305B-3B93-8215-8918C2CC45AF + 15828
 libdispatch.dylib    188FA8F6-305B-3B93-8215-8918C2CC45AF + 75172
 libdispatch.dylib    _dispatch_main_queue_callback_4CF + 44
 CoreFoundation       ED1BC017-D925-394E-B6D5-FA291931A668 + 354064
 CoreFoundation       ED1BC017-D925-394E-B6D5-FA291931A668 + 342292
 CoreFoundation       CFRunLoopRunSpecific + 608
 GraphicsServices     GSEventRunModal + 164
 UIKitCore            E8A673BA-FD1B-3FFD-9BBA-CC76D2E7F68C + 4238056
 UIKitCore            UIApplicationMain + 340
 tNotes               main + 100
 dyld                 A319655A-936B-3FB7-B5C2-5B06BAE36599 + 250196
)

I am preparing a small demo project and will send this on once done to show my process, but essentially I am saving the image from ASDraw with
B4X:
'save image to a file
    Dim Out As OutputStream
    If result = "Question" Then
        'save the image file
        Out = File.OpenOutput(Main.fileDir, img & "-Q" & Question & ".png", False)  
        'save the list to a file                     
        File.WriteList(Main.fileDir,Main.projectID & "-Q" & Question & ".lst",ASDraw1.ExportDrawing)
        nList.Clear
    Else
        'save the image file
        Out = File.OpenOutput(Main.fileDir, img & "-A" & Answer & ".png", False)                   
        'save the list to a file
        File.WriteList(Main.fileDir,Main.projectID & "-A" & Answer & ".lst",ASDraw1.ExportDrawing)
        nList.Clear
    End If
    ASDraw1.ImageComplete.WriteToStream(Out, 70, "PNG")
    Out.Close

Then reading the file back in
B4X:
Dim newList As List = File.ReadList(Dir,textFile)       
'for testing, loop through list file to make sure it has all the content needed       
Log("Contents of " & Main.projectname)
For Each i As Object In newList
    Log(i)   
Next
        
ASDraw1.ImportDrawing(newList,True)

I am not a developer so happy to learn from my mistakes and be guided on the best approaches!
 
Upvote 0

marconotsopolo

Member
Licensed User
And this is the content of the saved file
B4X:
Contents of Q0811240839
NSMapTable {
[7] stroke_color -> -16777216
[14] draw_path -> [_points=<B4IList: (
    "[IsInitialized=0, X=609, Y=215.0292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=593, Y=227.5292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=576, Y=248.5292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=488.5, Y=422.5292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=478.5, Y=526.5292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=509, Y=628.5292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=563.5, Y=654.5292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=642.5, Y=633.0292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=726, Y=532.0292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=751.5, Y=416.5292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=742, Y=342.5292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=695, Y=283.5292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=640.5, Y=254.0292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=583.5, Y=249.0292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=537, Y=270.0292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=503, Y=317.5292\n, ColumnData=(null)]"
)>, _dataready=0, _bounds=<B4XRect: (null)>
, _internalcounterclockwise=0, _drawconnectionsegments=1]
[15] stroke_width -> 5
}
NSMapTable {
[7] stroke_color -> -16777216
[14] draw_path -> [_points=<B4IList: (
    "[IsInitialized=0, X=640.5, Y=431.5292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=645, Y=448.5292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=649.5, Y=470.5292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=685.5, Y=635.5292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=710, Y=715.0292\n, ColumnData=(null)]"
)>, _dataready=0, _bounds=<B4XRect: (null)>
, _internalcounterclockwise=0, _drawconnectionsegments=1]
[15] stroke_width -> 5
}
NSMapTable {
[7] stroke_color -> -16777216
    "[IsInitialized=0, X=875, Y=249.0292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=878.5, Y=261.5292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=878.5, Y=280.5292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=878.5, Y=421.0292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=882.5, Y=529.0292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=885, Y=592.5292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=887, Y=611.5292\n, ColumnData=(null)]"
)>, _dataready=0, _bounds=<B4XRect: (null)>
, _internalcounterclockwise=0, _drawconnectionsegments=1]
[15] stroke_width -> 5
}
NSMapTable {
[7] stroke_color -> -16777216
[14] draw_path -> [_points=<B4IList: (
    "[IsInitialized=0, X=517.5, Y=820.5292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=528, Y=818.0292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=596.5, Y=804.0292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=847, Y=738.5292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=977.5, Y=692.0292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=1089, Y=660.0292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=1112.5, Y=657.5292\n, ColumnData=(null)]",
    "[IsInitialized=0, X=1102.5, Y=662.5292\n, ColumnData=(null)]"
)>, _dataready=0, _bounds=<B4XRect: (null)>
, _internalcounterclockwise=0, _drawconnectionsegments=1]
[15] stroke_width -> 5
}
 
Upvote 0

marconotsopolo

Member
Licensed User
OK, so resolved this by writing the file using randomaccessfile (writeb4xobject) and reading in using readb4xobject to maintain the list structure.
B4X:
'Write file'
Dim r As RandomAccessFile
    r.Initialize(File.DirDocuments,"test.lst",False)
    r.WriteB4XObject(ASDraw1.ExportDrawing,0)
   r.close
'Read File
Dim r As RandomAccessFile 
    r.Initialize(File.DirDocuments,"test.lst",True)
    Dim rs As Object
    rs = r.ReadB4XObject(0) 
    ASDraw1.ImportDrawing(rs,True)
    r.close
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…